TopBottom

Followers



Click on more
SUBSCRIBE

Enter your email address:

Delivered by FeedBurner



VIDEO

Announcement: wanna exchange links? contact me at ravikrak@yahoo.com

Introduction To Storage Classes

Posted by Ravi Kumar at Sunday, December 25, 2011
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

strong class provides information about their location and
visibility.The storage class decides the portion of the
program within which the variables are recognized.
A variables storage class tells us

1.where the variables would be stored.
2.What will be the initial value of the variable,if the
initial value is not specifically assigned.
3.What is the scope of the variable i.e., which functions
the value of the variable would be available.
4.What is the lifetime of the variable, i.e., how long the
variable exist.
There are 4 types of storage classes in C.
1.Automatic
2.Static
3.External
4.Register

Share |

Labels:

Problems In Structures

Posted by Ravi Kumar at
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

typedef struct
{
int data;
NODEPTR link;
}*NODEPTR;
A typedef defines a new name for a type and in similar
cases like the one shown below you can define a new
structure type and a typedef for it at the same time.
typedef struct
{
char name[20];
int age;
}emp;
typedef struct
{
int data;
NODEPTR link;
}*NODEPTR;
There is no error in this because a typedef declaration
cannot be used until it is defined.In the given code
fragment the typedef declaration is not yet defined at the
point where the link file is declared.To eliminate this
problem ,first give the structure a name("struct node").Then
declare the link field as a simple struct node as shown
below:

typedef struct node

{
int data;
struct node *link;
}*NODEPTR;
Another way to eliminate this problem is to disentangle
the typedef declaration from the structure definition as
struct node
{
int data;
struct node *link;
};
typedef struct node *NODEPTR;
Another way is to precede the struct declaration with the
typedef ,in which case we would use the NODEPTR typedef
when declaring the link field as
typedef struct node *NODEPTR
struct node
{
int data;
NODEPTR next;
};

In this case ,we declare a new typedef name involving
struct node even though struct node has not been completely
defined yet,this allowed to do.

2.void modify(struct emp *);
struct emp
{
char name[20];
int age;
};
main()
{
struct emp e={"sanjay",4};
modify( &e);
printf("\n %s%d",e.name,e.age);
}
void modify(struct emp *p)
{
strupr(struct emp *p)
p->age=p->age+2;
}

Share |

Labels:

Pointers And Structures In C Language

Posted by Ravi Kumar at
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

We know that the name of an array stands for the address of its zeroth element.The samething is true of the names of arrays of structure variables.Suppose product is an array variable of structtype.The name product represents the address of its zeroth element consider the following declaration.

struct inventory
{
char name[30];
int number;
float price;
} product[2],*ptr;
This statement declares product s an array of two elements,each of the type struct inventory and ptr as a pointer to data objects of the type struct inventory.
The assignment
ptr=product;
would assign the address of the zeroth element of
product to ptr.This is,the pointer ptr will now point to
product[0].Its members can be accessed using the following
notation.
ptr --> name
ptr--> number
ptr --> price
The symbol -->is called the arrow operator and is made
up of a minus sign and a greater than sign.Note that ptr-->
is simply another way f wrting product[0].When the pointer
ptr is incremented by one,it is made to point to the next
record. i.e,product[1].We could use the notation
(*ptr).number
to access the member number.The parantheses around *ptr
are necessary because the member operator "." has a
higher precedence than the operator *

A program to illustrate the use of a structure pointer
to manipulate the elements of an array of structures the
program highlights all the features discussed above.Note
that the pointer ptr(of type struct invert) is also used
as the loop control index in for loops

Share |

Labels: