C++指针的长度

本文探讨了不同字长计算机上C++指针的长度,包括32位和64位程序的区别,并通过示例代码展示了各种类型指针的大小。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

每台计算机的字长指明了它的虚拟空间大小.比如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;
}

  

posted on 2017-09-06 00:52 好吧,就是菜菜 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/shuiyonglewodezzzzz/p/7482704.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值