简体   繁体   English

指针地址存储器属于RAM还是硬盘驱动器?

[英]Pointer address memories belongs to RAM or Hard Drive?

#include <stdio.h>
int main() {
    int num=1234;
    printf("%p", &num);
    return 0;
}

//Ouput:
//0xffffcbfc

Is 0xffffcbfc a RAM or a Hard Drive address memory? 0xffffcbfc是RAM还是硬盘驱动器地址存储器?

That code is, strictly speaking, exhibiting undefined behavior. 严格来说,该代码表现出未定义的行为。 You must convert the pointer to void * since that's what %p expects: 您必须将指针转换为void *因为这正是%p期望:

printf("%p\n", (void *) &num);

And it's probably unspecified from C's point of view exactly what kind of physical device holds the address, but on a typical computer it's going to be RAM. 从C的角度来看,可能还不确定具体是哪种物理设备保存该地址,但是在典型的计算机上它将是RAM。

It's a stack address, which is notionally RAM. 这是一个堆栈地址,概念上是RAM。 It won't be a real physical RAM address (in modern systems) and really only reflects the bookkeeping the kernel does. (在现代系统中)它将不是真正的物理RAM地址,而实际上仅反映内核所做的记账工作。

Programs on computers that have a HD are always loaded into RAM by the OS and executed from there. 具有HD的计算机上的程序始终由OS加载到RAM中并从那里执行。 All addresses will point at RAM. 所有地址将指向RAM。

You cannot address HD memory directly from the program, you'll have to go through the file system. 您不能直接从程序中寻址HD内存,而必须浏览文件系统。

Strictly speaking, when printing the address of a variable the address you see is from the virtual memory (provided, in most cases you would be running your program on an OS which uses virtual memory ). 严格来说,在打印变量的地址时,您看到的地址来自虚拟内存(前提是,在大多数情况下,您将在使用虚拟内存的OS上运行程序)。

If your OS does not use a virtual memory, the address would be directly from the RAM. 如果您的操作系统不使用虚拟内存,则该地址将直接来自RAM。

To run a program, you have to load it into memory (RAM). 要运行程序,必须将其加载到内存(RAM)中。 In short, you will not get an address from your hard drive. 简而言之,您不会从硬盘驱动器上获得地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM