Loading...
C++ Program to Find Size of int, float, double and char in Your System

C++ Program to Find of Variables in Your System

In this example, we will Find Size of int, float, double and char in Your System using C++ cout statement.

Program to Add Two Numbers

In this program declares 4 variables of type int, float, double and char. Then, the size of each variable is evaluated using sizeof operator.

To find the size of variable,  sizeof operator is used.
The Syntax is:

sizeof(dataType);

Example: Program to Find Size of int, float, double and char

#include <iostream>
using namespace std;

int main() 
{    
    cout << "Size of char: " << sizeof(char) << " byte" << endl;
    cout << "Size of int: " << sizeof(int) << " bytes" << endl;
    cout << "Size of float: " << sizeof(float) << " bytes" << endl;
    cout << "Size of double: " << sizeof(double) << " bytes" << endl;

    return 0;
}

Output

Size of char: 1 byte
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes

Note: You may get different result if you are using a old computer / laptop.


Next Example

We hope that this Example helped you develop better understanding of the concept of Find the Size of int, float, double and char in C++.

Keep Learning : )

In the next Example, we will learn about C++ Swap Two Numbers.


- Related Topics