Operands for sizeof operator

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

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

filter_none

edit
close

play_arrow

link
brightness_4
code

sizeof (type-name) 

chevron_right


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



filter_none

edit
close

play_arrow

link
brightness_4
code

sizeof expression

chevron_right


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

filter_none

edit
close

play_arrow

link
brightness_4
code

#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);
  
 getchar();
 return 0;
}

chevron_right


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

References:
http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V40G_HTML/AQTLTCTE/DOCU0015.HTM
http://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#The-sizeof-Operator



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


9


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