C Sizeof Operator

The C Sizeof operator is one of the operators which is mostly useful to find the array size and structure size and do some calculations as per the results.

The sizeof operator returns the size (number of bytes) of a declared variable or data type. Let us see one C programming example for a better understanding.

C Sizeof Operator Example

In this Operator example program, We are going to check the size of an integer, float, character, double, and character array using sizeof operator.

#include <stdio.h>

int main()
{
  int a;
  int b[20];
 
  printf(" Size of int data type:%d \n ", sizeof(int) );
  printf(" Size of char data type:%d \n ", sizeof(char) );
  printf(" Size of float data type:%d \n ", sizeof(float) );
  printf(" Size of double data type:%d \n ", sizeof(double) );

  printf(" Size of int data type:%d \n ", sizeof(a) ); 
  printf(" Size of an int array:%d \n ", sizeof(b) );
  
  return 0;
}
C SizeOf Operator

The result of sizeof(b): Although we declared the size of the b as 20, it displays the output as 80. Because the b array will store 20 integer members. And every integer member needs 4 bytes of space ( means 20 * 4 Bytes for every integer member.)