The sizeof
operator provides information about the size of a data type in bytes.
#include <iostream>
using namespace std;
int main () {
cout << "size of bool:\t\t" << sizeof(bool) << " Byte / " << sizeof(bool) * 8 << " Bit" << endl;
cout << "size of char:\t\t" << sizeof(char) << " Byte / " << sizeof(char) * 8 << " Bit" << endl;
cout << "size of integer:\t" << sizeof(int) << " Byte / " << sizeof(int) * 8 << " Bit" << endl;
cout << "size of unsigned integer:" << sizeof(unsigned int) << " Byte / " << sizeof(unsigned int) * 8 << " Bit" << endl;
cout << "size of long integer:\t" << sizeof(long int) << " Byte / " << sizeof(long int)*8 << " Bit" << endl;
cout << "size of float:\t\t" << sizeof(float) << " Byte / " << sizeof(float) * 8 << " Bit" << endl;
cout << "size of double:\t\t" << sizeof(double) << " Byte / " << sizeof(double) * 8 << " Bit" << endl;
cout << "size of long long:\t" << sizeof(long long) << " Byte / " << sizeof(long long) * 8 << " Bit" << endl;
}
size of bool: 1 Byte / 8 Bit
size of char: 1 Byte / 8 Bit
size of integer: 4 Byte / 32 Bit
size of unsigned integer:4 Byte / 32 Bit
size of long integer: 8 Byte / 64 Bit
size of float: 4 Byte / 32 Bit
size of double: 8 Byte / 64 Bit
size of long long: 8 Byte / 64 Bit