G-Fact 12

In C, struct keyword must be used for declaring structure variables, but it is optional in C++.

For example, following program gives error in C and works in C++.

filter_none

edit
close

play_arrow

link
brightness_4
code

struct node {
   int x;
   node *next; // Error in C, struct must be there. Works in C++
};
  
int main()
{
   node a;  // Error in C, struct must be there. Works in C++
}

chevron_right


And following program works in both C and C++.



filter_none

edit
close

play_arrow

link
brightness_4
code

struct node {
   int x;
   struct node *next;  // Works in both C and C++
};
  
int main()
{
   struct node a;  // Works in both C and C++
}

chevron_right


Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.