C++指针的长度

每台计算机都有字长,指明指针数据的标称大小----来自深入理解计算机系统

每台计算机的字长指明了它的虚拟空间大小.比如32位的机器,虚拟空间地址为0~2^w-1程序最多访问2^w个字节

对于32位程序和64位程序的区别在于如何编译.

gcc -m32 编译成32位程序

gcc -m64 编译成64位程序.

对于32位程序,虚拟地址空间最大是4GB.

所以有,以后代码在不同字长的计算机运行的结果是不同的.32位是4

#include <iostream>
#include <stdio.h>
#include<memory.h>
using namespace std;

#define null NULL

int f1(int a)
{
	return a;
}
void f2(int a)
{
	cout<<a<<endl;
}
int main(int argc,char* argv[])
{
	freopen("C:\Users\zzzzz\Desktop\1.txt", "r", stdin);
	double* pd;
	char* pc;
	float* pf;
	long long* pll;
	int* pi;
	void* pv;
	int (*fi)(int);
	void (*fv)(int);
	cout<< sizeof(pd)<<endl;
	cout<<sizeof(pc)<<endl;
	cout<<sizeof(pf)<<endl;
	cout<<sizeof(pll)<<endl;
	cout<<sizeof(pi)<<endl;
	cout<<sizeof(pv)<<endl;
	cout<<sizeof(fi)<<endl;
	cout<<sizeof(fv)<<endl;
	cout<<sizeof(null)<<endl;
	return 0;
}

  

原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/7482704.html