为何两份代码的输出结果会有这样的差别?
程序代码:
#include<stdio.h> int main(void){ char ch; scanf("%c",&ch); while(ch!='g'){ printf("%c",ch); scanf("%c",&ch); } return 0; }
这段代码运行后,在控制台输入输出结果如下所示:
Go west,young man
Go west,youn
如果将代码改成下面这样:
程序代码:
#include<stdio.h> int main(void){ char ch; scanf("%c",&ch); while(ch!='g'){ printf("%c",ch); } return 0; }
运行后控制台的输入输出结果变成这样:
Go west,young man
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
不停的打印G
为何两份代码的输出结果会有这样的差别?