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

后端 未结 30 2858
旧时难觅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:17

    "condition" === (printf("Hello"), 0)
    

    Really lame:

    int main() {
        if  (printf("Hello"), 0)
            printf ("Hello");
        else
            printf("World");
    }
    

    I prefer the use of the comma operator because you don't have to look up the return value of printf in order to know what the conditional does. This increases readability and maintainability. :-)

提交回复
热议问题