Operands for sizeof operator


In C, sizeof operator works on following kind of operands:

1) type-name: type-name must be specified in parentheses.

   sizeof (type-name) 

2) expression: expression can be specified with or without the parentheses.

    sizeof expression

The expression is used only for getting the type of operand and not evaluated. For example, below code prints value of i as 5.

#include <stdio.h>

int main()
 int i = 5;
 int int_size = sizeof(i++);
 printf("\n size of i = %d", int_size);
 printf("\n Value of i = %d", i);

 return 0;

Output of the above program:
size of i = depends on compiler
value of i = 5


GATE CS Corner    Company Wise Coding Practice

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Recommended Posts:

1.8 Average Difficulty : 1.8/5.0
Based on 30 vote(s)