//break:退出整个switch语句 //如果case后面没有break,就会执行后面所有case中的语句,直到遇到break为止
#include <stdio.h>
int main() { /* int a = 5; switch (a) { case 5: printf("A\n"); break; case 10: printf("B\n"); break; case 1: printf("D\n"); break; default: printf("C\n"); break; } */ //如果要在case后面定义新的变量,那么必须把case后面用大括号{}包住 char c = '+'; int a = 10; int b = 20; switch(c) { case '+': {int sum = a + b; printf("%d\n",sum); break; } case '-': { int minus = a - b; printf("%d\n",minus); break; } } return 0; }
|