linux - Why won't this code permute the value Z? -
so trying build simple program in c permutes value of z
(z
equal x + y
) every single thing try differently doesn't work. frustrated here. please me understand.
source:
#include <stdio.h> #include <stdlib.h> int main() { int x, y, z; scanf("%d", &x); scanf("%d", &y); z = x + y; printf("%d", &z); return 0; }
you're printing address of z
, not stored value, because you're passing printf
pointer z
rather value. change printf
line to:
printf("%d", z);
scanf
returns success value has use way give input. argument you're passing (&x
) pointer variable want use storage. that's ampersand for. says "use address of variable".
printf
, on other hand, wants values themselves. doesn't need address. (though, technically, strings passed in pointers. not distinction need worry right now.)
Comments
Post a Comment