本文介绍了默认情况下,在开关状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的code:

  #include<stdio.h>
  int main()
  {
      int a=10;
      switch(a)
      {
      case '1':
          printf("ONE\n");
          break;
      case '2':
          printf("TWO\n");
          break;
      defalut:
          printf("NONE\n");
      }
      return 0;
  }

程序不显示任何信息,甚至没有。我想通了,默认有一个错字 defalut !结果
我想知道为什么不被编译器检测到该语法错误。

The program doesn't print anything, not even NONE. I figured out that default had a typo defalut!
I want to know why this syntax error is not detected by the compiler.

推荐答案

defalut 仅仅是在你的程序的标签,你可以跳转到与转到。具有突出的关键字编辑会犯这样的错误更容易被发现。

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.

我也应该注意到,你的程序可能有一些逻辑错误。字符 1 是不一样的 1 ,并用'一样2 2

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.

这篇关于默认情况下,在开关状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 09:29