如题,测试如下:
代码:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "char:" << sizeof(char) << endl;
cout << "pointer:" << sizeof(char *) << endl;
cout << "int:" << sizeof(int) << endl;
cout << "long:"<< sizeof(long) << endl;
cout << "long long:" << sizeof(long long) << endl;
cout << "float:" << sizeof(float) << endl;
cout << "double:" << sizeof(double) << endl;
}
(1) 32位环境
操作系统: win7
编译环境: vc
结果:
char:1
pointer:4
int:4
long:4
long long:8
float:4
double:8
(2)64位环境
操作系统: SUSE
编译环境:gcc
结果:
char:1
pointer:8
int:4
long:8
long long:8
float:4
double:8
由此可见:除了指针类型和long类型以外,其它类型的长度在两种环境下都相同
32位环境中,指针类型长度是4个字节,长整形是4个字节
64位环境中,指针类型长度是8个字节,长整形是8个字节