C default 关键字
示例
指定当 switch 语句块中没有匹配项时要执行的代码:
int day = 4;
switch (day) {
case 6:
printf("Today is
Saturday");
break;
case 7:
printf("Today is Sunday");
break;
default:
printf("Looking forward to the Weekend");
}
// Outputs
"Looking forward to the Weekend"
亲自试一试 »
定义和用法
default 关键字指定 switch 语句中的默认代码块,该代码块是在 switch 语句中没有 case 匹配项时要运行的代码。
注意: 如果 default 关键字用作 switch 块中的最后一个语句,则不需要 break。
相关页面
请阅读C语言Switch教程,了解更多关于switch语句的内容。

