X86和X64環境下的基本類型所佔用的字節大小

一樣的程序代碼,使用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;
}
目標平臺爲X86,編譯後運行結果:

目標平臺爲X64,編譯後運行結果:

相關文章
相關標籤/搜索