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;
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM