C Program to Find the Size of int, float, double and char

In this tutorial, we will write a program to display the size of every data type using sizeof operator in C. Before that, you may go through the following topics in c as it is used in the program.


sizeof() operator in C

The sizeof operator in C is commonly used to determine the size of an expression or data type. It returns the size of the memory allocated to that data type.

C Program to find the size of data types

#include<stdio.h>

int main() 
{
    int intVar;
    float floatVar;
    double doubleVar;
    char charVar;

    //size of each variables
    printf("Size of the Variables in bytes:\n");
    printf("int: %zu\n", sizeof(intVar));
    printf("float: %zu\n", sizeof(floatVar));
    printf("double: %zu\n", sizeof(doubleVar));
    printf("char: %zu\n", sizeof(charVar));
    
    return 0;
}

Output:

Size of the Variables in bytes:
int: 4
float: 4
double: 8
char: 1