同样的程序代码,使用Visual Studio 进行编译,当目标平台分别为x86或x64环境时,其编译结果是不同的。在x86环境下,指针都是4个字节的;而在x64环境下,指针都是8字节的。测试代码如下:
#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;
}