我知道执行后的printf返回一些非零值{编辑:返回否.charecters}现在在这个例子中我使用了多个printf和现在.
/* As far as i was cocerned Precedence of && is more than ||,
*and these logical operators check from left to right
*So compiler should come to hello and print "hello" then "nice to see you" then "hie"
*as all are true it should print "hola"
*but i wonder, why here the output is only "hie" and "hola"?
*/
#include<stdio.h>
main()
{
if(printf("hie")|| printf("hello")&& printf("nice to see you"))
printf("\thola\n");
}
Run Code Online (Sandbox Code Playgroud)
成功时printf()返回写入的字符总数.因此printf("hie")返回3,这足以对逻辑"或"条件进行惰性评估.
printf("hie")|| printf("hello")
// --> 3 || whatever -->
// true || whatever -->
// true
Run Code Online (Sandbox Code Playgroud)
因此,根本不需要进行评估printf("hello").