struct node{
struct node next;
int id;
}
gives “field next has incomplete type error “.
what is wrong with this struct ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When creating a self-referential data type, you need to use pointers to get around problems of circularity:
…should work, but take care to allocate memory correctly when using it.
Why a pointer? Consider this: the point of a
structdefinition is so that the compiler can figure out how much memory to allocate and what parts to access when you saynode.id. If yournodestruct contains anothernodestruct, how much memory should the compiler allocate for a givennode?By using a pointer you get around this, because the compiler knows how much space to allocate for a pointer.