一張圖:數據類型在不同位平臺和編譯器下sizeof的字節大小

先看源碼。

#include <iostream>
using namespace std;

struct MyStruct
{
	char    a;
	int		b;
	double  c;
	char *  d;
};

int main() 
{
	cout << "short int:" << sizeof(short int) << endl;
	cout << "int:" << sizeof(int) << endl;
	cout << "unsigned int:" << sizeof(unsigned int) << endl;
	
	cout << "long:" << sizeof(long) << endl;
	cout << "unsigned long:" << sizeof(unsigned long) << endl;
	cout << "long long:" << sizeof(long long) << endl;

	cout << "float:" << sizeof(float) << endl;

	cout << "double:" << sizeof(double) << endl;

	cout << "char:" << sizeof(char) << endl;
	cout << "char*:" << sizeof(char*) << endl;

	cout << "struct MyStruct:" << sizeof(MyStruct) << endl;

	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章