What if I don't write default in switch case?

后端 未结 8 657
一向
一向 2020-12-13 17:09
int a = 10;
switch(a){
case 0:
    printf(\"case 0\");
    break;
case 1:
    printf(\"case 1\");
    break;
}

Is the above code valid?

If

8条回答
  •  遥遥无期
    2020-12-13 17:38

    It is perfectly legal code. If a is neither 0 or 1, then the switch block will be entirely skipped.

提交回复
热议问题