Open In App

GFact | Use of struct keyword in C and C++

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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++.




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++
}


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




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



Last Updated : 17 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads