且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Printf(“%d”)

更新时间:2022-09-21 20:20:51

What’s the output result of the following code snippet?

Printf(“%d”)
char foo() 
{
    unsigned int a = 6;
    int b = -20;
    char c;
    printf("%d  ", a + b);
    (a + b > 6) ? ( c = 1 ) : ( c = 0 );
    return c;
}
 
main() 
{
    char b = foo();
    printf("%d",b);
    getch();
}
Printf(“%d”)

unsigned int + int = unsigned int, so a + b = 4294967282
printf("%d"), print as signed, so -14( = 4294967282 as unsigned)

printf(“%u”), print as unsigned int


本文转自zdd博客园博客,原文链接:http://www.cnblogs.com/graphics/archive/2010/04/20/1715865.html,如需转载请自行联系原作者