c++中 指针占几个字节

通过一段代码进行测试:

#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
	int a = 1;
	int *p1 = &a;
	cout << "int " << sizeof(p1) << endl;
	float b = 1.23;
	float *p2 = &b;
	cout << "float " << sizeof(p2) << endl;
	double c = 1.3456;
	double *p3 = &c;
	cout << "double" << sizeof(p3) << endl;
	system("pause");
	return 0;
	

}

在WIN32编译器下

在x64编译器下

由此得出结论:

指针在Win32下的大小为4字节

x64下的大小为8字节

猜你喜欢

转载自blog.csdn.net/qq_31442743/article/details/81628058