[英]Confusion about the output
#include<stdio.h>
int main(void)
{
int i=1,j=-1;
if((printf("%d",i))<(printf("%d",j)))
printf("%d",i);
else
printf("%d",j);
return 0;
}
As printf()
returns the number of characters successfully printed, the condition will be if(1<1)
which is false but the if part is executed and the output is 1 -1 1
. 当printf()
返回成功打印的字符数时,条件将为if(1<1)
,该条件为false,但执行了if部分,输出为1 -1 1
。 Why this is happening? 为什么会这样呢?
I think it is rather obvious: '1' is one character, '-1' is two. 我认为这很明显:“ 1”是一个字符,“-1”是两个字符。 One is less than two. 一小于二。
Because printing j prints "-1", that's two characters. 因为打印j会打印“ -1”,所以这是两个字符。 so 1<2 is true. 所以1 <2是正确的
对于-1
,如果满足条件,则打印的字符数为2
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.