Loading...
C Program to find the Size of datatypes

C Program to Find the Size of Data Types

In this example, we will learn to find the size of each datatypes like int, float, char and double using sizeof operator.

Remainder :

To understand this example, you must have the knowledge of the following C programming topics:


Program to Find the Size of datatypes

#include<stdio.h>

int main() {
  int intData;
  float floatData;
  char charData;
  double doubleData;
  printf("Size of int is %zu bytes\n", sizeof(intData));
  printf("Size of float is %zu bytes\n", sizeof(floatData));
  printf("Size of char is %zu byte\n", sizeof(charData));
  printf("Size of double is %zu bytes\n", sizeof(doubleData));
  return 0;
}

Output

Size of int is 4 bytes
Size of float is 4 bytes
Size of char is 1 byte
Size of double is 8 bytes

Working of the above program

  • First we declare integer variable intData, float variable floatData, char variable charData and double variable doubleData to further calculate their size.
  • int intData;
    float floatData;
    char charData;
    double doubleData;
  • Finally we get the size of the variables of different datatype in first step using sizeof() function.
  •   printf("Size of int is %zu bytes\n", sizeof(intData));
      printf("Size of float is %zu bytes\n", sizeof(floatData));
      printf("Size of char is %zu byte\n", sizeof(charData));
      printf("Size of double is %zu bytes\n", sizeof(doubleData));

- Related Topics