在 printf 行程序自行结束后,但我不明白为什么。
#include<stdio.h>
int main ()
{
int Sum,multiply,divide,difference,num1,num2;
char i;
scanf("%d", &s1);
scanf("%d", &s2);
printf("Type initial of your operation : ");
scanf("%c", &i);
return 0 ;
}
最佳答案
您无法编译它,因为 s1
和 s2
是 undefined variable 。
因此,有关您运行它时发生的情况的任何信息都是没有意义的,因为您无法运行它。
你的意思是:
if(scanf("%d %d", &num1, &num2) == 2)
{
printf("Operands are %d and %d, now type initial of desired operation:\n");
if(scanf("%c", &i) == 1)
{
}
}
在依赖返回值之前检查 scanf()
是否成功非常重要。
关于c - printf 程序结束后不执行其余代码? C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21597756/