#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 !!
#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 !!
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.
Processes on systems with virtual memory always deal with virtual addresses. You wouldn't be able to use a physical address from within a process.
This is most easily verified by making the program run in a loop and print the value with some delay, then running multiple copies of the same program. Chances are they will print the same address (unless the OS is randomizing the virtual address usage), which of course would be impossible if the addresses were physical.