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

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

    Two possible Solutions without using printf statements :-

    First :-

    #include 
    
    int
    main(void)
    {
      if (!stdin || (stdin = 0, main()))
        printf("hello");
      else
        printf("world");
      return 0;
    }
    

    Second

    #include
    void main()
    {
    if (1
    #define else if (1) 
    )
    { 
      printf("hello"); 
    } 
    else
     { 
        printf("world"); 
    }
    }
    

    Reference :- Link1 , Link2

提交回复
热议问题