struct node
{
int data;
struct node *next;
}
cout<<sizeof(struct node)<<sizeof(node)<<endl;
//no error, C++ allows us to use sizeof(struct node) and sizeof(node) both.
Whereas we cannot do the same with int datatype
int a;
cout<<sizeof(int) <<sizeof(a) <<endl;//there is no error here
//BUT
cout<<sizeof(int a) <<endl;//this throws an error
I understand that "struct node" itself is like a datatype which can be used to declare variable of type "struct node". Going by the behavior of how sizeof() works with int, it is understandable that sizeof(struct node) is equivalent to sizeof(datatype) and hence is correct usage.
But how does sizeof(node) work as well ? It does not throw any error. "node" in itself cannot be used to declare any other variables, it needs to be "struct node" to declare a variable.