What's the “condition” in C interview test?

后端 未结 30 2871
旧时难觅i
旧时难觅i 2020-12-05 02:37

Would it be possible to print Hello twice using single condition?

if  \"condition\"
  printf (\"Hello\");
else
  printf(\"World\");         


        
30条回答
  •  暖寄归人
    2020-12-05 02:52

    The if statement executes one or the other of the controlled statements (both printf in your example). No matter what you use for condition, that snippet will either print "Hello", or "World", but never both.

    Edit: Okay, so it's a trick question and you can put whatever you like in the condition (including a call to an entire other function that does anything you want). But that's hardly interesting. I can't believe I got downmodded for giving a correct answer.

提交回复
热议问题