int a;
printf("%d",sizeof a);// fine
printf("%d",sizeof int);// giving parse error here
can any one help me in this regard.

When using the sizeof operator with a type name, it must be enclosed within parentheses.

can you explain why is that required?

can you explain why is that required?

I always figured that it is because type names can consist of more than one token, like sizeof(long double) , but variable names are always one token. The parentheses make parsing multiple tokens easier. I cannot think of a good place where the behavior would change between sizeof(long double) and sizeof long double if the parentheses were optional, but C's syntax is wacky enough that I am sure there is one. ;)


SUMMARY: The 'sizeof' operator is used to determine the amount of space any data-element/datatype occupies in memory. To use sizeof, the keyword "sizeof" is followed by a type name, variable, or expression. If a type name is used , it always needs to be enclosed in parentheses, whereas variable names and expressions can be specified with or without parentheses.