标题:关于sizeof和size_t再次置顶
取消只看楼主
周ok
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-10-13
 问题点数:0 回复次数:0 
关于sizeof和size_t再次置顶
关于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”?
搜索更多相关主题的帖子: sizeof 置顶 
2009-10-20 08:48



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




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

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