sizeof检测数据类型

#include<math.h>
#include<stdio.h>
#include <string.h>
#include<iostream> 
using namespace std;

typedef struct
{
	unsigned char  uc1;
	unsigned char  uc2;
	unsigned char  uc3;
	unsigned char  uc4;
	unsigned char  uc5;
	unsigned char  uc6;
	unsigned long long int  i1;
	unsigned char  uc7[2];
}uc_t;

void sizeof_zh()
{
	uc_t aa;
	cout <<"aa "<<sizeof(aa)<<endl;
	
	cout<<"float = "<< sizeof(float)<<endl;//4
	cout<<"double = "<< sizeof(double)<<endl;//8
	cout<<"int8/char = "<< sizeof(char)<<endl;//1
	cout<<"int16/short int = "<< sizeof(short int)<<endl;//2
	cout<<"int32/int = "<< sizeof(int)<<endl;//4
	cout<<"int32/long int = "<< sizeof(long int)<<endl;//4
	cout<<"int64/long long int = "<< sizeof(long long int)<<endl;//8
}

结果:
1> aa 24
1> float = 4
1> double = 8
1> int8/char = 1
1> int16/short int = 2
1> int32/int = 4
1> int32/long int = 4
1> int64/long long int = 8
sizeof(数据类型):记录数据类型所占字节

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值