vc++常见数据类型所占字节空间总结(VS2008 64位系统)

char类型:

char cPos;
unsigned char ucPos;
char str[] = "Hello" ;
char *pChar = str;
char *pCharArray[10][10];
cout <<"char:"<<sizeof(cPos)<< endl;//1
cout <<"unsigned char:"<<sizeof(ucPos)<< endl;//1
cout <<"str[]:"<<sizeof(str)<< endl;//6
cout <<"*pCharArray[10][10]:"<<sizeof(pCharArray)<< endl;//400

short类型
short sClass;
unsigned short usClass;
short sLevel[6];
cout <<"short:"<<sizeof(sClass)<< endl;//2
cout <<"unsigned short:"<<sizeof(usClass)<< endl;//2
cout <<"short sLevel[6]:"<<sizeof(sLevel)<< endl;//12


long类型

long lIndex;
unsigned long ulGrade;
cout <<"long:"<<sizeof(lIndex)<< endl;//4
cout <<"unsigned long:"<<sizeof(ulGrade)<< endl;//4

double类型

double	dWeight;
long double ldWeight;
cout <<"double:"<<sizeof(dWeight)<< endl;//8
cout <<"long double:"<<sizeof(ldWeight)<< endl;//12

int类型

int pi;
unsigned int upi;
cout <<"int:"<<sizeof(pi)<< endl;//4
cout <<"unsigned int:"<<sizeof(upi)<< endl;//4

union类型

typedef union record
{
    long lIndex;
    short sLevel[6];
    char cPos;
} REC_S;

typedef union empty
{} EMPTY;
cout <<"union record:"<<sizeof(stMax)<< endl;//12
cout <<"union *pMax:"<<sizeof(pMax)<< endl;//4
cout <<"union empty:"<<sizeof(em)<< endl;//1
cout <<"union *emp:"<<sizeof(emp)<< endl;//4

struct类型,有点复杂,对字节对齐还不太熟悉,继续了解

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值