C++ size of double – Size of int c++ – C++ Program to Find Size of Int, Float, Char and double data types using sizeof operator

Size of int c++: In the previous article, we have discussed C++ Program to Find Average of Numbers Using Arrays. In this article, we will see C++ Program to Find Size of Int, Float, Char and double data types using sizeof operator.

C++ Program to Find Size of Int, Float, Char and double data types using sizeof operator

  • Write a program in C++ to find the size of variables in run time using size of operator.
  • How to find the size of Integer, Character, floating point and Double data type variables in C++.

C++ program to find size of variable using sizeof operator

C++ size of double: In this program, we will use sizeof operator to find the size of variable at run-time. The size of variable is system dependent. Hence, the output of below program may differ depending upon the system configurations.

sizeof Operator
The sizeof is a compile time operator not a standard library function. The sizeof is a unary operator which returns the size of passed variable or data type in bytes.
As we know, that size of basic data types in C++ is system dependent, So we can use sizeof operator to dynamically determine the size of variable at run time.

C++ program to find size of variable using sizeof operator

/*
* C++ Program to find Size of char, int, float, and double
* in Your System uisng sizeof operator
*/
#include <iostream>
 
using namespace std;
 
int main() {
    // Printing size of Basic Data Types
    cout << "Size of a Character (char) = " << sizeof(char) << " bytes" << endl;
    cout << "Size of an Integer (int) = " << sizeof(int) << " bytes" << endl;
    cout << "Size of a Floating Point (float) = " << sizeof(float) << " bytes" << endl;
    cout << "Size of Double (double) = " << sizeof(double) << " bytes" << endl;
 
    return 0;
}

Output

Size of a Character Variable (char) = 1 bytes
Size of an Integer Variable (int) = 4 bytes
Size of a Floating Point Variable (float) = 4 bytes
Size of Double Variable (double) = 8 bytes

Start writing code in C++ language by referring to Simple C++ Program Examples available here. These examples are helpful to get an idea on the format, function used in every basic program.