How Are C Arrays Represented In Memory?

后端 未结 8 689
醉话见心
醉话见心 2020-12-14 01:33

I believe I understand how normal variables and pointers are represented in memory if you are using C.

For example, it\'s easy to understand that a pointer Ptr will

相关标签:
8条回答
  • 2020-12-14 02:18

    Your diagram is correct. The weirdness around &x has nothing to do with how arrays are represented in memory. It has to do with array->pointer decay. x by itself in value context decays into a pointer to its first element; i.e., it is equivalent to &x[0]. &x is a pointer to an array, and the fact that the two are numerically equal is just saying that the address of an array is numerically equal to the address of its first element.

    0 讨论(0)
  • 2020-12-14 02:20

    int x[] produces the same result as int* x;

    it's just a pointer

    therefore notations x[i] and *(x + i) produce the same result.

    0 讨论(0)
提交回复
热议问题