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

Determining the size of different data types in C++ is an essential task that programmers need to perform.

The size of data types varies from one system to another, and hence it is important to determine the size of data types for a specific system.

In this tutorial, we will see how to find the size of int, float, double, and char data types in a C++ program.

In C++, the sizeof operator is used to determine the size of a data type. The sizeof operator returns the number of bytes allocated for a data type.

The syntax for using the sizeof operator is as follows:

sizeof(data_type)

Now, let us see how to find the size of int, float, double, and char data types in a C++ program.

#include <iostream>
using namespace std;

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

In the above program, we have used the sizeof operator to determine the size of int, float, double, and char data types.

We have printed the size of each data type using the cout statement.

When we run the above program, we will get the output as follows:

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

The size of the int and float data types is 4 bytes each, the size of the double data type is 8 bytes, and the size of the char data type is 1 byte.

It is important to note that the size of data types may vary depending on the system architecture.

In conclusion, determining the size of data types is an essential task in programming.

In this tutorial, we have seen how to find the size of int, float, double, and char data types in a C++ program using the sizeof operator.