在C语言里面default是什么意思用法是怎么用表示什么命令。

来源:百度知道 编辑:UC知道 时间:2024/05/21 04:35:30

请先看一下面程序:(注:请输入>0的整数)

main()
{
int a;
printf("please input a:\n");
scanf("%d",&a);
switch(a)
{
case 1:
printf("Input small than 3\n");
break;
case 2:
printf("Input small than 3\n");
break;
default:
printf("Error! Input is >=3");

}
}
看完上面的程序想必你已明白了许多,default的作用就是switch语句里所有的case都不成立时所要执行的语句。

是switch语句里所有的case都不成立时执行的东西

switch里面的缺省值
例子:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int i;
cin >> i;
switch (i)
{
case (1):
cout << "1\n";
break;
default:
cout << "default\n";
}
return 0;
}

switch语句中的默