468,117 Members | 1,528 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,117 developers. It's quick & easy.

Struct in struct

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
1 3061
Niheel
2,418 Expert Mod 2GB
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.

Similar topics

5 posts views Thread by Roy Hills | last post: by
10 posts views Thread by Rick Anderson | last post: by
19 posts views Thread by Russell Shaw | last post: by
16 posts views Thread by burn | last post: by
5 posts views Thread by Johs32 | last post: by
7 posts views Thread by Alex | last post: by
4 posts views Thread by hugo.arregui | last post: by
4 posts views Thread by Sheldon | last post: by
13 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.