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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -