Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Address of (&) gives compiler generated address or loader generated address?

int a;
printf("address is %u", &a);

Which address is this..? I mean is this a compiler generated address i.e. virtual address or the loader given physical address in the RAM..?

As it prints different address every time, I guess it must be address in the RAM. Just want to make sure.

Please provide any links which give reference to your answer.

like image 460
Adorn Avatar asked Jan 18 '23 06:01

Adorn


1 Answers

The address returned for a local variable in the user space is always a virtual address not the physical address.

The variable a in your case is allocated on the local storage(stack) and every time you execute your program a stack space allocated to your function, the variable is located at particular offset within this stack frame, since the address of the stack being allocated to your program can be different everytime the address returned for the variable will be different as well.

like image 145
Alok Save Avatar answered Jan 20 '23 15:01

Alok Save