我是编程学习C语言的新手.我现在很困惑.我试图谷歌,但无法找到令人满意的结果,所以我想通过在这个网站上提问来解决.
看看这个简短的节目
#include<stdio.h>
int main()
{
int num1,num2;
printf("enter the value of num1 and num2:");
scanf("%d %d",&num1,&num2);
printf("num1 = %d and num = %d",num1,num2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我输入值例如 - 215-15没有space或new line没有它给出输出num1 = 215和num2 = -15但当我输入space或new line介于215-和15之间然后它给出输出num1 = 215和num2 = -175436266(或任何意外数).
我知道当scanf()读取任何不在转换规范类别中的字符时,它会放回该字符并结束处理其他输入.但在第一种情况下-(minus sign),根据转换规范似乎是无关紧要的输入,但它显示正确的输出但在后一种情况下它没有显示正确的输出.为什么?