A program uses different regions of memory for static objects, automatic objects, and dynamically allocated objects

后端 未结 4 2013
滥情空心
滥情空心 2020-12-09 17:57

I am following the book \"C Primer Plus\" and encounter a problem to understand the regions of memory. In the book, it states:

Typically, a p

4条回答
  •  借酒劲吻你
    2020-12-09 18:20

    I want to try and explain this in a more simple way.

    0x... is a hexadecimal string that represents a string of binary bits. You can think of it as representing a number, but shorthand because you don't need to know the number, just it's relative value to other similarly coded numbers. So this means that the "address value" is actually just a number.

    Why use numbers to represent memory locations? Because for all intents and purposes, memory is just a really large byte array, who's values can be read by index. C logically (not physically) divides this memory array into different sections for efficient storage. So the closer 2 address locations are in memory, the closer they are together in that byte array representation.

    The address range available to any application is determined at runtime, and is not actually any part of specific memory spaces. So in all fairness, there is no why to know for sure that certain items are in a certain memory region. Just that it is highly statistically implausible for 2 objects close together in memory to be in different regions.

提交回复
热议问题