C pointers and the physical address

前端 未结 11 787
傲寒
傲寒 2020-12-03 15:43

I\'m just starting C. I have read about pointers in various books/tutorials and I understand the basics. But one thing I haven\'t seen explained is what are the numbers.

11条回答
  •  眼角桃花
    2020-12-03 16:47

    It's the address of the pointer.

    "anumber" takes up some space in RAM, the data at this spot contains the number 10.

    "apointer" also takes up some space in RAM, the data at this spot contains the location of "anumber" in RAM.

    So, say you have 32 bytes of ram, addresses 0..31

    At e.g. position 16 you have 4 bytes, the "anumber" value 10

    At e.g. position 20 you have 4 bytes, the "apointer" value 16, "anumber"'s position in RAM.

    What you print is 20, apointer's position in RAM.

    Note that this isn't really directly in RAM, it's in virtual address space which is mapped to RAM. For the purpose of understanding pointers you can completely ignore virtual address space.

提交回复
热议问题