c++基础类型所占字节

c++基础类型所占字节,第1张

win32位 x86

	cout << sizeof(short) << endl;
	cout << sizeof(int) << endl;
	cout << sizeof(long) << endl;
	cout << sizeof(long long) << endl;

	cout << sizeof(float) << endl;
	cout << sizeof(double) << endl;
	cout << sizeof(long double) << endl;

	cout << sizeof(char) << endl;

	cout << sizeof(int *) << endl;
	cout << sizeof(float *) << endl;
	
	cout << sizeof(int[1]) << endl;
	cout << sizeof(int[2]) << endl;
	cout << sizeof(float[2]) << endl;
	

结果:

2
4
4
8
4
8
8
1
4
4
4
8
8

win64位 x64

cout << sizeof(short) << endl;
	cout << sizeof(int) << endl;
	cout << sizeof(long) << endl;
	cout << sizeof(long long) << endl;

	cout << sizeof(float) << endl;
	cout << sizeof(double) << endl;
	cout << sizeof(long double) << endl;

	cout << sizeof(char) << endl;

	cout << sizeof(int *) << endl;
	cout << sizeof(float *) << endl;
	
	cout << sizeof(int[1]) << endl;
	cout << sizeof(int[2]) << endl;
	cout << sizeof(float[2]) << endl;

结果:

2
4
4
8
4
8
8
1
8
8
4
8
8

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/872725.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-13
下一篇2022-05-13

发表评论

登录后才能评论

评论列表(0条)

    保存