1
#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?

4 Answers4

6

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.

unwind
  • 391,730
  • 64
  • 469
  • 606
1

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.

Joe
  • 7,378
  • 4
  • 37
  • 54
1

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.

Lundin
  • 195,001
  • 40
  • 254
  • 396
1

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.

babon
  • 3,615
  • 2
  • 20
  • 20