Default case in a switch condition

前端 未结 3 1830
太阳男子
太阳男子 2020-12-03 17:04

I have this code:

  #include                                   
  int main()
  {   
      int a=10;
      switch(a)
      {   
      case \'1\         


        
相关标签:
3条回答
  • 2020-12-03 17:16

    defalut is just a label in your program that you can jump to with goto. Having an editor that highlights keywords could have made this error easier to spot.

    I should also note that your program may have some logic errors. The character '1' is not the same as 1, and the same with '2' and 2.

    0 讨论(0)
  • 2020-12-03 17:25

    That's not a syntax error. defalut is a valid label, and it could be the target of a goto.

    0 讨论(0)
  • 2020-12-03 17:33

    tip: if you are using gcc, add the option -pedantic. it will warn you for unused labels:

    $ gcc -ansi -Wall -pedantic test.c -o test
    test.c: In function ‘main’:
    test.c:14:10: warning: label ‘defalut’ defined but not used
    
    0 讨论(0)
提交回复
热议问题