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

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

    It's same like no if condition is matched and else is not provided.

    default is not an mandatory in switch case. If no cases are matched and default is not provided, just nothing will be executed.

提交回复
热议问题