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

Last Updated : 12 Aug, 2026

In this article, we will learn how to find the size of int, float, double, and char data types in C++. The sizeof() operator helps determine the memory occupied by a data type or variable.

  • The size of a data type is measured in bytes.
  • The actual size can vary depending on the compiler and system architecture.

Finding the Size of Data Types Using sizeof()

The sizeof() operator returns the size of a data type or variable in bytes.

Syntax

sizeof(dataType);

sizeof int, double, char, float

To find the size of the four datatypes:

  • Declare variables of type int, float, double, and char.
  • Use the sizeof() operator to determine the size of each variable.
  • Print the results.

C++ Program to Find the Size of a Data Types

C++
#include <iostream>
using namespace std;

int main()
{
    int integerType;
    char charType;
    float floatType;
    double doubleType;

    // Calculate and Print
    // the size of integer type
    cout << "Size of int is: " << sizeof(integerType)
         << "\n";

    // Calculate and Print
    // the size of doubleType
    cout << "Size of char is: " << sizeof(charType) << "\n";

    // Calculate and Print
    // the size of charType
    cout << "Size of float is: " << sizeof(floatType)
         << "\n";

    // Calculate and Print
    // the size of floatType
    cout << "Size of double is: " << sizeof(doubleType)
         << "\n";

    return 0;
}

Output
Size of int is: 4
Size of char is: 1
Size of float is: 4
Size of double is: 8

Note: The size of a data type is implementation-defined and may vary across systems. For example, int is commonly 4 bytes, but the C++ standard does not require it to be exactly 4 bytes.

Try It Yourself
redirect icon
Comment