一樣的程序代碼,使用Visual Studio 進行編譯,當目標平臺分別爲x86或x64環境時,其編譯結果是不一樣的。在x86環境下,指針都是4個字節的;而在x64環境下,指針都是8字節的。測試代碼以下:ios
#include<iostream> using namespace std; int main(int argc, char** argv) { cout << "sizeof(char)=" << sizeof(char) << endl << "sizeof(char*)=" << sizeof(char*) << endl << "sizeof(short)=" << sizeof(short) << endl << "sizeof(short*)=" << sizeof(short*) << endl << "sizeof(int)=" << sizeof(int) << endl << "sizeof(int*)=" << sizeof(int*) << endl << "sizeof(long)=" << sizeof(long) << endl << "sizeof(long*)=" << sizeof(long*) << endl << "sizeof(long long)=" << sizeof(long long) << endl << "sizeof(long long*)=" << sizeof(long long*) << endl << "sizeof(float)=" << sizeof(float) << endl << "sizeof(float*)=" << sizeof(float*) << endl << "sizeof(double)=" << sizeof(double) << endl << "sizeof(double*)=" << sizeof(double*) << endl; return 0; }