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?

Upvotes: 1

Views: 875

Answers (4)

babon
babon

Reputation: 3774

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).

If your OS does not use a virtual memory, the address would be directly from the RAM.

To run a program, you have to load it into memory (RAM). In short, you will not get an address from your hard drive.

Upvotes: 1

Lundin
Lundin

Reputation: 214730

Programs on computers that have a HD are always loaded into RAM by the OS and executed from there. All addresses will point at RAM.

You cannot address HD memory directly from the program, you'll have to go through the file system.

Upvotes: 1

Joe
Joe

Reputation: 7818

It's a stack address, which is notionally RAM. It won't be a real physical RAM address (in modern systems) and really only reflects the bookkeeping the kernel does.

Upvotes: 1

unwind
unwind

Reputation: 400029

That code is, strictly speaking, exhibiting undefined behavior. You must convert the pointer to void * since that's what %p expects:

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.

Upvotes: 6

Related Questions