C++ Example - View the Size of int, float, double and char Variables
Use the C++ sizeof operator to calculate the amount of space occupied by int, float, double, and char variables.
sizeof operator syntax format:
sizeof(dataType);
Note:Different systems may produce different calculation results.
Example
#include <iostream>
using namespace std;
int main()
{
cout << "char: " << sizeof(char) << "byte" << endl;
cout << "int: " << sizeof(int) << "byte" << endl;
cout << "float: " << sizeof(float) << "byte" << endl;
cout << "double: " << sizeof(double) << "byte" << endl;
return 0;
}
The output result of the above program execution is:
char: 1 字节 int: 4 字节 float: 4 字节 double: 8 字节other extensions