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

后端 未结 8 650
一向
一向 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:41

    Default is not mandatory but always good to have it. The code is ideally but our life is not, no harm to put a protection there. It will also help you debugging if any unexpected thing happens.

提交回复
热议问题