Confusion about the output

前端 未结 4 1113
挽巷
挽巷 2021-01-25 10:05
#include
int main(void)
{
    int i=1,j=-1;
    if((printf(\"%d\",i))<(printf(\"%d\",j)))
        printf(\"%d\",i);
    else 
        printf(\"%d\",j);         


        
相关标签:
4条回答
  • 2021-01-25 10:37

    For -1 number of characters printed is 2 hence if condition is satisfied.

    0 讨论(0)
  • 2021-01-25 10:44

    I think it is rather obvious: '1' is one character, '-1' is two. One is less than two.

    0 讨论(0)
  • 2021-01-25 10:50

    Because printing j prints "-1", that's two characters. so 1<2 is true.

    0 讨论(0)
  • 2021-01-25 11:00

    printf returns the number of characters (not just digits) written.

    So printf("%d",-1) will return 2 not 1

    Similarly printf("%d",1) will return 1

    Making the condition in the if true.

    0 讨论(0)
提交回复
热议问题