Swicth case语句不加break的后果

265 阅读1分钟

    #include <stdio.h>
#include <stdlib.h>

int main(int argc, char ** argv)
{
int value = 0;

switch(value)
{
case 0:
printf("case 0\n");
case 1:
printf("case 1\n");
case 2:
printf("case 2\n");
}
return 0;
}
//case里如果不加break,不管后面case条件是否满足都会执行;

输出

    case 0
case 1
case 2
————————————————