void display()
{
printf("every thing is ok");
}
void main()
{
int ch;
while(1)
{
printf("enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1: clrscr();printf("when choice is one every thing is fine");
display();
break;
case 2: clrscr();printf("when chice is two its confusing");
display();
break;
case 3: exit(0);
default: printf("enter choice as 1 or 2 or to exit enter 3");
}
}
}
当我跟踪这个 C 程序并输入选项 2 时,它会从 case 1 block 调用显示函数。我不明白。请回复并解释一下。我真的很困惑。
最佳答案
编译器可能正在重新排列您的源语句,从而折叠其 basic blocks 。然后,调试器会将这两种情况下对 display()
的调用匹配到相同的源代码行号。当启用优化时,这是常见的情况。
关于c switch 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4327869/