I want to know how scanf
works. Difference In working of scanf
when dealing with integer input and character input.
int main()
{
int x , y ;
printf("Enter A Number x : ");
scanf("%d" , &x);
printf("Enter Any Number Y : ");
scanf("%d" , &y);
return 0;
}
In The Above Program Output is Enter A Number X : I enter a number .Then it again ask for any number y. I enter that number and program terminates.
But in the program written below it ask for character . I enter a character. After That it again ask for a character, but it terminates without giving me an option to enter a character .
int main()
{
char x , y ;
printf("Enter A char x : ");
scanf("%c" , &x);
printf("Enter Any char Y : ");
scanf("%c" , &y);
return 0;
}
I know that when I entered first character and pressed enter .
That enter get stored in the keyboard buffer memory and next scanf
takes that value in and does not let me enter it.
But Why does this thing not happen in integer case ?