标题:关于sizeof和size_t再次置顶
只看楼主
周ok
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-10-13
 问题点数:0 回复次数:0 
关于sizeof和size_t再次置顶
// sizeof.c -- uses sizeof operator
// uses C99 %z modifier -- try %u or %lu if you lack %zd
#include <stdio.h>
int main(void)
{
    int n = 0;
    size_t intsize;
  
    intsize = sizeof (int);
    printf("n = %d, n has %u bytes; all ints have %u bytes.\n",
         n, sizeof n, intsize );
         
    return 0;
}
结果:n=0, n has 2 bytes; all ints have 2 bytes.


修改后:
// sizeof.c -- uses sizeof operator
// uses C99 %z modifier -- try %u or %lu if you lack %zd
#include <stdio.h>
int main(void)
{
    int n = 0;
    size_t intsize;
  
    intsize = sizeof (int);
    printf("n = %d, n has %u bytes; all ints have %u bytes.\n",
         n, sizeof n, intsize );
         
    return 0;
}
结果:n=0, n has 0 bytes; all ints have 4 bytes.

为什么“n has 0 bytes”?

   

[ 本帖最后由 周ok 于 2009-10-14 09:42 编辑 ]
搜索更多相关主题的帖子: include return 
2009-10-13 10:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-288321-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.116615 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved