#include <stdio.h>
int main() {
int i;
printf("%d",scanf("%d",&i));// > What does this explain
return 0;
}
It returns 1 every time. How?
#include <stdio.h>
int main() {
int i;
printf("%d",scanf("%d",&i));// > What does this explain
return 0;
}
It returns 1 every time. How?
scanf()
return the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.
The value EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs. EOF is also returned if a read error occurs, in which case the error indicator for the stream (see ferror(3)) is set, and errno is set indicate the error.
Please read the man: https://linux.die.net/man/3/scanf
You're printing out the return value of scanf()
-- which returns the number of items formatted.
Try:
#include <stdio.h>
int main() {
int i;
scanf("%d", &i);
printf("%d", i);
return 0;
}
As another commenter mentioned, however, you should look up the documentation on these functions and experiment with them instead of immediately asking for help on something so easy to answer. Take a look at this website: http://www.cplusplus.com/reference/cstdio/scanf/