“printf” only printing variable addresses

后端 未结 2 1870
青春惊慌失措
青春惊慌失措 2021-01-27 03:45

so here is my code:

#include 
main(){
int hi;
hi = 3;
printf(\"%d\",&hi);
}

and the output is: \"2686748\"

im using

相关标签:
2条回答
  • 2021-01-27 04:00

    If you intend to print the value of hi, just pass it to printf, not its address:

    printf("%d", hi);
    

    You may be confusing printf with scanf, the latter requiring all of its arguments to be pointers.

    0 讨论(0)
  • 2021-01-27 04:01

    The "%d" tells the printf you are putting in an integer. The integer you are giving it is &hi which is the address of hi. If you want the value of hi just use that

    0 讨论(0)
提交回复
热议问题