TopBottom

Followers



Click on more
SUBSCRIBE

Enter your email address:

Delivered by FeedBurner



VIDEO

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

Problems In Structures

Posted by Ravi Kumar at Sunday, December 25, 2011
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:

0 comments:

Post a Comment