Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When we associate '&' with a variable the address we get is the virtual address or the physical address? [duplicate]

#include<stdio.h>
 int main()
 {
   int a;
   printf(" %u ",&a);
   return 0;
 }

The address we get is the virtual address of the process or the physical address when the process is running in main memory. Please help I am confused !!

like image 367
user3111412 Avatar asked Jan 27 '14 13:01

user3111412


1 Answers

If you run the program on a system with virtual memory, you will get a virtual address. If you run on a system without virtual memory (typically smaller embedded systems), you will get a physical address.

Also note that the format "%u" is wrong for pointers, if you want to use printf to print a pointer you should use "%p". See e.g. this reference.

like image 101
Some programmer dude Avatar answered Oct 07 '22 19:10

Some programmer dude