I want to create a structure comprising of an integer and a pointer to it. However it doesnt seem to work and devC++ gives the following error

struct loha
{
       int i;
       int *p = &i;   ...7
} *pp;                ...8

Error : 7 I:\G\My CPP\structures.c [Warning] no semicolon at end of struct or union
7 I:\G\My CPP\structures.c syntax error before '=' token
8 I:\G\My CPP\structures.c [Warning] data definition has no type or storage class


In other words i want to know how to refer to a structure within the same structure..?? i am sure &i is not the write syntax.. what can be the possible correction.??

Thanks in advance .!

try int *p instead of int *p = &i;

But that wont make it point to 'i' in every instance of the structure..

When you create a structure, you just define what type of data is containing. In this case, an integer and a pointer to integer.

When you create the pointer to structure (pp), just initialize:
pp->p=&(pp->i);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.