Skip to content
Home » C Program to Find Size of Data Types

C Program to Find Size of Data Types

Learn about C Program to Find Size of Data Types in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C Program to Find Size of Data Types

The size of data types in C is determined by the compiler or system architecture, i.e. 32-bit or 64-bit compiler. The data type int has a size of 2 bytes in 32-bit architecture and 4 bytes in 64-bit architecture.

A sizeof() function implemented under stdio is required to determine the size. h. sizeof() returns the size in bytes. A 0 or a 1 takes up one bit of space. 1 byte is equal to 8 bits. We can use sizeof() to determine the size of data-types or variables.

Program:

#include<stdio.h>
int main()
{
   printf("Size of short is %ld bytes\n",sizeof(short));
   printf("Size of int is %ld bytes\n",sizeof(int));
   printf("Size of long is %ld bytes\n",sizeof(long));

   printf("Size of char is %ld bytes\n",sizeof(char));
   printf("Size of void is %ld bytes\n",sizeof(void));

   printf("Size of float is %ld bytes\n",sizeof(float));
   printf("Size of double is %ld bytes\n",sizeof(double));
   printf("Size of long double is %ld bytes\n",sizeof(long double));
   return 0;
}

Output:

Size of short is 2 bytes
Size of int is 4 bytes
Size of long is 8 bytes
Size of char is 1 bytes
Size of void is 1 bytes
Size of float is 4 bytes
Size of double is 8 bytes
Size of long double is 16 bytes

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Hello World Program in C
Print 1 to 10 numbers without Loop in Python