struct node { struct node x; //not allowed struct node *head; //allowed }; Why does we can declare a pointer of same type but not a variable of same type?
struct node { struct node x; //not allowed struct node *head; //allowed }; Why does we can declare a pointer of same type but not a variable of same type?
EmbLogic Research & Competency Development Labs
Phone: +91 9818467776, 8527567776, 9650467776
Email: info@emblogic.com
Copyright © EmbLogic Embedded Technologies Pvt. Ltd.
See it this way.. When we declare a pointer it tells the compiler to allocate space for the pointer, which is of structure type in your case it’s self referential.
But if you take a variable same as the structure it will have an endless chain. Let The struct that you have declared be allocated memory. Then that space will be having a pointer and a variable of the same struct type be it x. But x must also be having a pointer and a stuct variable of its type, thus it will create an endless chain…. Hence tis type of declaration is only imaginary