How to print variable addresses in C?

前端 未结 5 1294
孤独总比滥情好
孤独总比滥情好 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:33

    To print the address of a variable, you need to use the %p format. %d is for signed integers. For example:

    #include
    
    void main(void)
    {
      int a;
    
      printf("Address is %p:",&a);
    }
    

提交回复
热议问题