32位64位下各种数据类型大小的对比

1.基本数据类型大小的对比

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// C++Test.cpp : 定义控制台应用程序的入口点。  
//

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;


//main
int _tmain(int argc, _TCHAR* argv[])
{
cout << "sizeof(char):" << sizeof(char) << endl;
cout << "sizeof(short):" << sizeof(short) << endl;
cout << "sizeof(int):" << sizeof(int) << endl;
cout << "sizeof(long):" << sizeof(long) << endl;
cout << "sizeof(long long):" << sizeof(long long) << endl;
cout << "sizeof(unsigned int):" << sizeof(unsigned int) << endl;
cout << "sizeof(float):" << sizeof(float) << endl;
cout << "sizeof(double):" << sizeof(double) << endl;
void* pointer;
cout << "sizeof(pointer):" << sizeof(pointer) << endl;

system("pause");
return 0;
}

看一下结果:

WIN32下:

sizeof(char):1
sizeof(short):2
sizeof(int):4
sizeof(long):4
sizeof(long long):8
sizeof(unsigned int):4
sizeof(float):4
sizeof(double):8
sizeof(pointer):4

请按任意键继续. . .

x64下:

sizeof(char):1
sizeof(short):2
sizeof(int):4
sizeof(long):4
sizeof(long long):8
sizeof(unsigned int):4
sizeof(float):4
sizeof(double):8
sizeof(pointer):8

结果

结论:在win下有区别的只有指针类型长度

32位和64位系统在Windows下基本数据类型的大小都是一样的。只有指针的大小不一样!32位指针大小为4byte,而64位的指针大小为8byte。

注:Linux下,long型是64位的,这一点是和Windows不同的地方。

PS:64位系统下是可以运行32位程序的。但是反过来的话是运行不了的。