How are virtual addresses assigned?

Take this C code for example

#include <stdio.h>
#include <stdlib.h>

int main() {

    int x;
    int* y = (int *) malloc(10*sizeof(int));

    printf("%p\n",&x);
    printf("%p\n",y);
    printf("%p\n",&(y[1]));

    while(1);

    return 0;
}

What will print virtual addresses that look something like this.

0x7ffd4e96d214

0x908010

0x908014

Will the virtual addresses be different each time the binary file starts, which made me think, how is the virtual address actually determined for the program?

+4
source share
1 answer

This is - perhaps - the effect of ASLR .

The solution should - as indicated in the ranking of the address space layout - be random.

+4
source

All Articles