Need help solving a C-based programming puzzle

前端 未结 5 1959
栀梦
栀梦 2021-01-13 14:32

I came across this puzzle here. I can\'t figure out why NONE is not printed. Any ideas?

#include
int main()
{
      int a=10;         


        
5条回答
  •  一个人的身影
    2021-01-13 15:11

    If defa1ut is a typo for default and the string "NONE" is printed:

    This is because '1' and 1 is different.

    '1' means the ASCII value of the character '1' whose value in decimal is 49. and 1 is an integer.

    The first case will be true if the value of a is 49 or '1' , but as a=10 so it is neither equal to '1' nor equals to '2' and thus default is executed (if it existed, and defa1ut is not a typo).

    If defa1ut is not a typo for default and simply nothing is printed:

    In this case you have no default instead which look like it is defa1ut which will act as a normal label, so simply nothing will be printed.

提交回复
热议问题