C++Primer第五版第四章练习4.28

C++程序:测量不同内置类型占用的字节数
该程序展示了如何在C++中使用sizeof运算符来计算bool、char等算术类型以及wchar_t、char16_t、char32_t等特殊字符类型的存储空间大小。
/*
练习4.28:
编写程序,输出每一种内置类型所占空间的大小。
答:
内置类型包括算术类型和空类型。
算术类型包括整型和浮点型:
bool、char、wchar_t、char16_t、char32_t、short、
int、long、long long、float、double、long double
*/
#include "TouWenJian_4.h"

int main()
{
	cout<<"1、bool size of bytes : \t\t"<<sizeof(bool)<<" bytes"<<endl<<endl;
	cout<<"2、char size of bytes : \t\t"<<sizeof(char)<<" bytes"<<endl<<endl;
	cout<<"3、wchar_t size of bytes : \t\t"<<sizeof(wchar_t)<<" bytes"<<endl<<endl;
	cout<<"4、char16_t size of bytes : \t\t"<<sizeof(char16_t)<<" bytes"<<endl<<endl;
	cout<<"5、char32_t size of bytes : \t\t"<<sizeof(char32_t)<<" bytes"<<endl<<endl;
	cout<<"6、short size of bytes : \t\t"<<sizeof(short)<<" bytes"<<endl<<endl;
	cout<<"7、int size of bytes : \t\t\t"<<sizeof(int)<<" bytes"<<endl<<endl;
	cout<<"8、long size of bytes : \t\t"<<sizeof(long)<<" bytes"<<endl<<endl;
	cout<<"9、long long size of bytes : \t\t"<<sizeof(long long)<<" bytes"<<endl<<endl;
	cout<<"10、float size of bytes : \t\t"<<sizeof(float)<<" bytes"<<endl<<endl;
	cout<<"11、double size of bytes : \t\t"<<sizeof(double)<<" bytes"<<endl<<endl;
	cout<<"12、long double size of bytes : \t"<<sizeof(long double)<<" bytes"<<endl<<endl;
	
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值