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

后端 未结 30 2864
旧时难觅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条回答
  •  萌比男神i
    2020-12-05 03:15

    This sounds to me like some interview puzzle. I hope this is close to what you want.

    
    #include 
    
    int main()
    {
     static int i = 0 ;
     if( i++==0 ? main(): 1)
      printf("Hello,");
     else
      printf("World\n");
    
     return 0 ;
    }
    

    prints Hello, World

提交回复
热议问题