Address of a variable in C program

#include <stdio.h>

main()
{
    int i = 5;
    printf("%d n" , &i);
}

重复执行上述程序是否会导致变量i地址不同?


Yes it can. Here's an explanation from a similar question:

It signifies that your program is being loaded a different (virtual) address each time you run it. This is a feature called Address Space Layout Randomization (ASLR) and is a feature of most modern operating systems.

from here: Why address of a variable change after each execution in C?


Yes it will change!

Pointers are used to store the address of a variable and address of a variable may change every time you execute the program.


Yes for the most every time a program gets loaded into Virtual Memory by your operating system the chances are the memory address of the program will get relocated every single time. So hence every time you print address of the variable it will be different every time it runs.

链接地址: http://www.djcxy.com/p/82496.html

上一篇: 全局指针变量如何存储在内存中?

下一篇: C程序中变量的地址