How to print variable addresses in C?

前端 未结 5 1287
孤独总比滥情好
孤独总比滥情好 2020-11-29 23:32

When i run this code.

#include 

void moo(int a, int *b);

int main()
{
    int x;
    int *y;

    x = 1;
    y = &x;

    printf(\"Addr         


        
5条回答
  •  天命终不由人
    2020-11-30 00:09

    You want to use %p to print a pointer. From the spec:

    p The argument shall be a pointer to void. The value of the pointer is converted to a sequence of printing characters, in an implementation-defined manner.

    And don't forget the cast, e.g.

    printf("%p\n",(void*)&a);
    

提交回复
热议问题