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

后端 未结 30 2872
旧时难觅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 03:09

    #define CONDITION (0) if (0) {} else
    

    or some such.

    If you see such a question on an interview, run away as fast as you can! The team that asks such questions is bound to be unhealthy.

    Edit - I forgot to clarify - this relies on "else" being matched with closest open "if", and on the fact that it's written as "if CONDITION" rather than if (CONDITION) - parenthesis would make the puzzle unsolvable.

提交回复
热议问题