0

I have seen use of size of operator without parenthesis.

For example

int x,y;
y = sizeof x;
  1. what is the difference between sizeof(x) and sizeof x?
  2. And why sizeof int does not work like sizeof(int)?
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740

1 Answers1

0

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.