0

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 .!

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by oieronle
0

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

0

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);

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.