0

I am new to c programming I am trying to understand structs concept in c in many tutorial they explained how to declare structs with this below example

 struct node
    {
      int data;
      int value;
    }

I under stand the above case ,but in the case below case they declared a struct inside it

 struct node
{
    int data;
    struct node *next;  \\ what is this?  why they declared like it ?
}
Arun karthi Mani
  • 100
  • 1
  • 3
  • 15
  • 1
    Thats not a nested struct. The last member of the struct `node` is a *pointer* to a type of `struct node`. – Toby Apr 27 '15 at 15:41

1 Answers1

1

Nested structure in C is nothing but structure within structure. One structure can be declared inside other structure as we declare structure members inside a structure. The structure variables can be a normal structure variable or a pointer variable to access the data.


Here's some statements about nested structures:

  • Structure written inside another structure is called as nesting of two structures.
  • Nested Structures are allowed in C Programming Language.
  • We can write one Structure inside another structure as member of another structure.

Also you might need to use "forward declaration" of node before.

Here's a good explanation and example are given: Nested struct in C language

tema
  • 1,115
  • 14
  • 33