By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,670 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,670 IT Pros & Developers. It's quick & easy.

Struct in struct

P: 12
I have seen this is mainly linked lists ... something like

struct NodeType
{
int current
NodeType *next
}

So you are obviously able to use the struct within itself?
Nov 11 '05 #1
Share this Question
Share on Google+
1 Reply


Expert Mod 100+
P: 2,328
No you can't use a struct within itself. That is illegal.

A struct can contain a pointer to itself, and that is what the example you are showing is doing.

Expand|Select|Wrap|Line Numbers
  1.  
  2. // illegal 
  3. struct dog
  4. {
  5. int age;
  6. struct dog male;    /* illegal */
  7. struct dog female;    /* illegal */
  8. };
  9.  
  10.  
  11. // legal and useful
  12. struct dog
  13. {
  14. int age;
  15. struct dog *next; /* legal */
  16. }
  17.  
Nov 21 '05 #2

Post your reply

Sign in to post your reply or Sign up for a free account.