プログラミング出力各組み込みタイプの長さ


手順は次のとおりです.
int main(/*int argc, char *argv[]*/)
{
	cout << "type\t\t\t" << "size" << endl
		<< "bool\t\t\t" << sizeof(bool) << endl
		<< "char\t\t\t" << sizeof(char) << endl
		<< "signed char\t\t" << sizeof(signed char) << endl
		<< "unsigned char\t\t" << sizeof(unsigned char) << endl
		<< "wchar_t\t\t\t" << sizeof(wchar_t) << endl
		<< "short\t\t\t" << sizeof(short) << endl
		<< "signed short\t\t" << sizeof(signed short) << endl
		<< "unsigned short\t\t" << sizeof(unsigned short) << endl
		<< "int\t\t\t" << sizeof(int) << endl
		<< "signed int\t\t" << sizeof(signed int) << endl
		<< "unsigend int\t\t" << sizeof(unsigned int) << endl
		<< "long\t\t\t" << sizeof(long) << endl
		<< "sigend long\t\t" << sizeof(signed long) << endl
		<< "unsigned long\t\t" << sizeof(unsigned long) << endl
		<< "float\t\t\t" << sizeof(float) << endl
		<< "double\t\t\t" << sizeof(double) << endl
		<< "long double\t\t" << sizeof(long double) << endl;
	return 0;
}

結果は次のとおりです.
type                    size bool                    1 char                    1 signed char             1 unsigned char           1 wchar_t                 2 short                   2 signed short            2 unsigned short          2 int                     4 signed int              4 unsigend int            4 long                    4 sigend long             4 unsigned long           4 float                   4 double                  8 long double             8
注意:
sizeはバイトの長さであり、1バイトは8ビットである.
short型を例にとると、上出力short型は2バイト、すなわち16ビットであり、格納されたデータ範囲は-2^15~2^15-1である.