Why does the variable address change after every execution in C?

int i=10;
printf("Address of i = %u",&i);

Output:
Address if i = 3220204848

Output on re-execution:
Address of i = 3216532594

I get a new address ievery time I run the program. What does this mean?

+3
source share
4 answers

This means that every time you load your program, a different (virtual) address is loaded. This feature, called Address Layout Randomization (ASLR) , is a feature of most modern operating systems.

+7
source

. , () ( , , , , ). , , , , , .

, , . , , , , , , ( == ) .

+1

c . , .

0

, , .

-

- https://www.quora.com/Do-pointer-addresses-change-every-time-the-program-is-executed-in-C

- https://www.quora.com/profile/Michael-Veksler

- . (Windows Linux), .

. , , ( , DOS, ).

, , , , , . , , , .

, [1]. , , . .

, . Linux , 0 /proc/sys/kernel/randomize_va_space. , ,

$ setarch uname -m -R program_path Linux . Linux, .

Windows Vista, , Windows 7 . , HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\MoveImages /DYNAMICBASE: NO. . , Visual Studio.

, C . , Linux Windows, , . , MS-DOS, .

0

Source: https://habr.com/ru/post/1745724/


All Articles