sizeof测试字节数c语言,C语言中sizeof()求字节数的应用举例 -电脑资料

本文尽可能多的测试了在win32平台下用sizeof()求各种类型变量字节数的结果,而且会不断更新,

sizeof(char)=1

sizeof(short)=2

sizeof(int)=4

sizeof(long)=4

sizeof(float)=4

sizeof(double)=8

sizeof(long double)=8

sizeof(unsigned char)=1

sizeof(unsigned short)=2

sizeof(unsigned int)=4

sizeof(unsigned long)=4

sizeof(unsigned float)=4

sizeof(unsigned double)=4

sizeof(unsigned long double)=8

char a[] = {'a','b','c','d','e'};//sizeof(a)=5

char b[] = "abcde";//sizeof(b)=6

char c[][3] = {{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'}};

//sizeof(c)=12

//sizeof(c[0])=3

//sizeof(c[0][0])=1

char d[][5] = {"abcc","deff","ghii","jkll"};

//sizeof(d)=20

//sizeof(d[0])=5

//sizeof(d[0][0])=1

char *p = 0;//sizeof(p)=4

char *q = (char *)malloc(5);//sizeof(q)=4

char *r = "abcde";//sizeof(r)=4

char (*f)(void) = NULL;//sizeof(f)=4

char *s1[3] = {"aa","bb","cc"};

//sizeof(s1)=12

//sizeof(s1[0])=4

//sizeof(*s1[0])=1

char *s2[3][3] = {{"aa","bb","cc"},{"aa","bb","cc"},{"aa","bb","cc"}};

//sizeof(s2)=36

//sizeof(s2[0])=12

//sizeof(*s2[0])=4

char h[3][3] = {{1,2,3},{4,5,6},{7,8,9}};

char (*ph)[3] = h;

//sizeof(ph)=4

//sizeof(*ph)=3

//sizeof(ph[0])=3

//sizeof(*ph[0])=1

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值