Sizeof Operator in C programming language

Spread the love

sizeof operator in c programming language

Sizeof Operator in C programming:

  • sizeof operator used to calculate the sizeof variable, constant or datatype
  • its unary operator means works on a single operand
  • sizeof operator returns the size of given input

Syntax :

result = sizeof(typeName)

typeName can be variable, constant or datatype.

Example :

printf(“Size of Integer : %ld \n”, sizeof(int))

Output :

Size of Integer: 4

Note: If you may thinking why I used %ld format specifier Because sizeof operator returns the output in size_t  format. it is an unsigned int  format.

Program to calculate the sizes of all data types :

Output :

Note: I am using GCC compiler on Ubuntu system with 64 bit OS. So if you use any other compiler like turbo C, your output might differ. But you need to note that sizes of datatypes are platform depended.

Fun Fact :

sizeof operator looks like a Function ( because of the parenthesis ) but it’s an operator.

 

Venkatesh Macha

Hi Guys, I am Venkatesh Macha. I am a programmer, Presently working as a Software Engineer. I love Linux and Open Source. Apart from that, I love to explore new technologies and things.

You may also like...

Leave a Reply