+ 1
I don’t understand, y output is 1
# include <stdio.h> int main(){ int x, s; x = scanf(“%d”, &x); s = x * x; printf(“%d”, s); return 0; } The output is 1, but I write 2 into scanf WHY?!
9 Réponses
+ 3
Probably because scanf returns 1. But either way, just scan it, you don't set x equal to the scanf function.
https://code.sololearn.com/cjRc22Ri14AE/?ref=app
+ 1
Look at the fix. I took away "x =" on line 5
+ 1
Матвей Барканов
"Ok, but how the meaning of scanf put into x?"
scanf("%d", &x 👈HERE)
0
Ok, but how the meaning of scanf put into x?
0
Oh, great! It’s working! Thank you! But y scanf returned 1?
0
I don't know, please use google. Plus, thats not the correct way to use scanf. The way i posted is. So use it right and you'll have no issues
0
Because he used assignment operator on scanf , so c compiler gets it as there is only one value entered so x=1 therefore after multiplication it stays as 1 so prints as 1 !!
0
scanf returns how many number of values it read.
int n = scanf("%d %d", &x, &y) ;
printf returns how many character it displayes on the output..
int y = printf("n=%d", n); //n=2
printf("%d", y) ; // 3
Hope it helps..
https://code.sololearn.com/cjh3dwj9kA34/?ref=app
- 2
Hii