This question already has an answer here:
- Pointer to pointer clarification 16 answers
IMPORTANT: This tried to ask too many things at once and was misleading because I wrote it under a false assumption about how pointers can be used, and it ended up just looking like a duplicate. Please see this instead: How are variables tied to their values in C?
Let's consider that there is a value 4
at address 0001
, and then we assign the address 0001
to the variable num
. We could visualize this as two tables:
VARIABLE|ADDRESS ADDRESS|VALUE
num |0001 0001 |4
From what I understand, this would be the end product of the following code:
int temp = 4;
int * num = &temp;
However, what is going on at the first line, int temp = 4;
? Does that first line produce something like this?
VARIABLE|ADDRESS ADDRESS|VALUE
| temp |4
And how do pointers to pointers work? Would the code:
int temp = 4;
int * num = &temp;
int ** pnum = #
produce this?
VARIABLE|ADDRESS ADDRESS|VALUE
num |0001 0001 |4
pnum |0002 0002 |0001
What is the right way to think of this? What is actually going on under the hood? Also, how does this change when a struct is stored instead of a number?
I understand that the above examples are probably entirely incorrect; they were simply to contextualize my question.