关于二级C的问题。

来源:百度知道 编辑:UC知道 时间:2024/05/07 02:41:29
#include<stdio.h>
main()
{int c;
c=3;
switch(c)
{case'1':printf("First!\n");
case'2':printf("Second!\n");
case'3':printf("Third!\n");break;
case'4':printf("Fourth!\n");
default:printf("Error!\n");
}
}

此程序具体怎么理解?
需要过程。

{int c; rem 定义变量C为整型
c=3; 赋值
switch(c) '条件判断语句
{case'1':printf("First!\n"); '如果C值为1 则打印First!
case'2':printf("Second!\n"); 同上
case'3':printf("Third!\n");break;
case'4':printf("Fourth!\n");
default:printf("Error!\n"); 全不满足则执行这句。

c值都固定为3了,那使用switch()还有什么意义?
程序直接输出Third就完了!

case '1'和下面的都要把‘’号去掉!因为C是整型,而case 后的加了''就成了字符数,所以会显示error