English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structures

C Language Files

C Others

C Language Reference Manual

C program to calculate the size of int, float, double, and char

Comprehensive Collection of C Programming Examples

In this example, you will learn to use the sizeof operator to evaluate the size of each variable.

Program to find the size of variables

#include<stdio.h>
int main() {
    int intType;
    float floatType;
    double doubleType;
    char charType;
    // Calculate the size of a variable using sizeof
    printf("The size of int: %ld bytes\n", sizeof(intType));
    printf("The size of float: %ld bytes\n", sizeof(floatType));
    printf("The size of double: %ld bytes\n", sizeof(doubleType));
    printf("The size of char: %ld bytes\n", sizeof(charType));
    
    return 0;
}

Output Result

The size of int: 4 bytes
The size of float: 4 bytes
The size of double: 8 bytes
The size of char: 1 bytes

In this program, the following variables are declared4variables intType, floatType, doubleType, and charType.

Then, use the sizeof operator to calculate the size of each variable.

Comprehensive Collection of C Programming Examples