What is difference between scanf(\"%d\")
and scanf(\"%d \")
in this code, where the difference is the trailing blank in the format string?
A white-space character (space, newline, horizontal and vertical tab) in a format string matches any number of white-space characters in the input.
In your first case
scanf("%d ",&j);
when it encounters the white-space char (WSC) ' '
then it will eat all the white spaces input by user including \n
on pressing Enter and it will expect to enter a non-WSC . In this case your program will terminate by pressing Ctrl + Z.