书法字典:https://www.shufadict.com

Printf(“%d”)

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

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();
}

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

posted on 2010-04-20 09:16  翰墨小生  阅读(929)  评论(0编辑  收藏  举报

导航

书法字典:https://www.shufadict.com