c - What is wrong on my code, I'm expected to print the output in int but it seems not? -
this code, , still keep on looking what's wrong, i'm beginner , want learn:
#include<stdio.h> int main() { int a; printf("input: "); scanf("%d", &a); printf("\n%d", &a); a+=2; printf("\n%d", &a); a+=4; printf("\n%d", &a); a+=2; printf("\n%d", &a); return 0; } here output:
input: 10 -1078169908 -1078169908 -1078169908 -1078169908
you don't need pass address of a printf() print content.
change
printf("\n%d", &a); to
printf("\n%d", a); also, should checking return value of scanf(). in case scanf() fails, you'll invoking undefined behavior accessing unitialized local variable.
that said, int main() should @ least int main(void) conform standards.
Comments
Post a Comment