Hello everyone! I'm newbie in programming learning C language.I'm little confused right now.I tried to Google about it but can not find out the satisfactory result so i thought to sort out by asking the question in this website.<br/>Have a look at this short program -
When i enter value For example- 215-15 without space or new line than it gives out num1 = 215 and num2 = -15 but when i enter space or new line between 215- and 15 then it gives output "num1 = 215 and num2 = -175436266(or any unexpected number).
I know that when scanf() reads any character which is not in the catagory of conversion specification it put back that character and end processing other inputs.But in the first case -(minus sign) seems to be irrelevent input according to the conversion specification but it shows correct output but in the later case it not showing correct output.Why?
Code:
#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;
}
I know that when scanf() reads any character which is not in the catagory of conversion specification it put back that character and end processing other inputs.But in the first case -(minus sign) seems to be irrelevent input according to the conversion specification but it shows correct output but in the later case it not showing correct output.Why?
Comment