How to print addresses in the C language?

In C language, you can use the & operator to get the address of a variable, and then use the %p format to output the address.

它是我的责任确保这个项目按时完成。

It is my responsibility to ensure that this project is completed on time.

#include <stdio.h>

int main() {
    int num = 10;
    printf("变量num的地址是:%p\n", &num);
    return 0;
}

The output result:

变量num的地址是:0x7ffee0b05b1c

In this example, &num gets the address of the variable num and then formats the output of the variable’s address using %p.

bannerAds