设为首页 加入收藏

TOP

C语言中sizeof()求字节数
2013-11-20 14:18:00 来源: 作者: 【 】 浏览:200
Tags:言中 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[] = {{'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[] = {"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 = {"aa","bb","cc"};

  //sizeof(s1)=12

  //sizeof(s1[0])=4

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

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

  //sizeof(s2)=36

  //sizeof(s2[0])=12

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

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

  char (*ph) = h;

  //sizeof(ph)=4

  //sizeof(*ph)=3

  //sizeof(ph[0])=3

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

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇CUDA函数库调用问题解决 下一篇C语言:编写访问PCI的小工具

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: