Print value and address of pointer defined in function?

后端 未结 5 1941
[愿得一人]
[愿得一人] 2021-02-07 23:29

I think this is a really easy thing to code, but I\'m having trouble with the syntax in C, I\'ve just programmed in C++.

#include 
#include 

        
5条回答
  •  隐瞒了意图╮
    2021-02-07 23:51

    int* iptr is already a pointer, so you don't need the & in front of it when you write

    printf("Address of iptr variable: %x\n", &iptr );
    

    This is how to print a pointer value.

    printf("Address of iptr variable: %p\n", (void*)iptr);
    

    Also you have the function prototype for pointerFuncA() in the wrong place, being inside main(). It should be outside of any function, before it is called.

提交回复
热议问题