I believe I understand how normal variables and pointers are represented in memory.
For example, it's easy to understand that a pointer Ptr will have one address, and its value will be a different address, which is the space in memory it's pointing to. The following code:
Would have the following representation in memory:Code:int main(){ int x = 10; int *Ptr; Ptr = &x; return 0; }
However I find it difficult to understand how arrays are represented in memory. For example the code:Code:+---------------------+-------------+---------+ | Variable Name | Address | Value | +---------------------+-------------+---------+ | x | 3342 | 10 | +---------------------+-------------+---------+ | Ptr | 5466 | 3342 | +---------------------+-------------+---------+
outputs the same address twice (for the sake of simplicity 10568). Meaning that x==&x. Yet *x (or x[0] in array notation) is equal to 12, *(x+1) (or x[1] in array notation) is equal to 13 and so on. How can this be represented? One way could be this:Code:int main(){ int x[5]; x[0]=12; x[1]=13; x[1]=14; printf("%p\n",x); printf("%p\n",&x); return 0; }
Is this close to what happens, or completely off?Code:+---------------------+-------------+----------+----------------------+ | Variable Name | Address | Value | Value IF array | +---------------------+-------------+----------+----------------------+ | x | 10568 | 10568 | 12 | +---------------------+-------------+----------+----------------------+ | | 10572 | | 13 | +---------------------+-------------+----------+----------------------+ | | 10576 | | 14 | +---------------------+-------------+----------+----------------------+