I have seen use of size of operator without parenthesis.
For example
int x,y;
y = sizeof x;
- what is the difference between
sizeof(x)
andsizeof x
? - And why
sizeof int
does not work likesizeof(int)
?
I have seen use of size of operator without parenthesis.
For example
int x,y;
y = sizeof x;
sizeof(x)
and sizeof x
?sizeof int
does not work like sizeof(int)
?Since sizeof
is a unary operator, it can be used before any variable or constant just like the unary operator '-' and typecast operator. So the parenthesis is not necessary if it is used with a variable or constant.
Just like -1
and -(1)
work.
But if it is used with a data type, missing the parenthesis will give compiler error.