when we print an address of a variable, which address gets printed?
if it is virtual memory, then why is it so?
can any one explain som开发者_开发技巧e more...
On modern desktop/server OSs, all memory is virtual memory. I'm not aware of any way to access the underlying physical addresses from outside of the kernel. Even if it is possible, it's not going to be useful in the vast majority of situations.
So, if you do printf("%p", (void*)&variable);
it will print the virtual address of variable for the current process.
The virtual memory address gets printed, and it is so because you don't have any need for the physical address, and the whole point of the OS is to prevent you from having to deal with physical addresses (well it's not only that, but it's also that :D).
On a normal PC computer, it is a value which you get if you convert poitner to integer of the same size.
void *p = something;
int i = *(int*)p;
printf("%x", i);
Memory address is virtual, yes of course, because that's how the process executing your code addresses the memory in your comupter. The process cannot see physical memory.
精彩评论