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

9 Years
Discussion Span
Last Post by __avd

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.