本文介绍了打印C指针的物理地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过使用以下code打印指针的地址

I can print the address of a pointer by using the following code

#include<stdio.
int main(){
    int *q =(int*) malloc(4);
    printf("%x\n",q);
}

当我执行以下code十六进制值被打印出来。它是虚拟地址或变量Q的堆的物理地址?如果是虚拟的我应该怎么打印其他?

When i execute the following code a hexadecimal value is printed. Is it the virtual address or the physical address of variable q on heap? If it is virtual how should i print the other?

推荐答案

这是在虚拟地址空间的条款。这是不可能得到在标准C物理地址(除非你不具有的虚拟内存,当然,一个系统,在这种情况下,它永远是物理地址) - 如果它是当前在交换空间举例来说,它甚至可能不会有一个,比在磁盘上的当前位置等,这不会是非常有用的你

It's in terms of virtual address space. It's impossible to get a "physical" address in standard C (unless you're on a system which doesn't have virtual memory, of course, in which case it'll always be the physical address) - if it's currently in swap space, for instance, it may not even have one, other than a current location on disk, which wouldn't be very useful to you.

这篇关于打印C指针的物理地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-08 18:15