我帮助在大学里教授计算机科学课程的介绍,我帮助的教授在学生面前给我测试,以确保我不认为这些问题太难或太混乱.他用以下代码给了我一个问题:
#include<stdio.h>
#include<stdlib.h>
int main(){
int x = 5;
switch(x){
case 3: x += 1;
case 4: x += 2;
case 5: x += 3;
case 6: x++;
case 7: x += 2;
case 8: x--;
case 9: x++;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我运行它时,我认为输出应该是10.但是,当运行时,它输出11.我在每种情况后放置print语句,输出如下所示:
8
9
11
10
11
11
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,有人可以解释一下吗?我觉得这是一件简单的事情,但我无法理解我的生活.
c ×1