I've read about pointers and watched some tutorials about it, but my understanding about is still shallow. To make up my mind I need to be clear my objective - what are the important terms that I need to know in this topic, and how they relate to each other.
I posted this so that you can probably improve my understanding regarding this topic, give an idea on how to remember or understand it in a new, more preferable way, or correct me if I get the wrong understanding anywhere in topic. Maybe, by just posting this, I can understand the topic even better than just by reading.
Here's the first three terms that I came across:
1. The reference (&) operator.
2. A pointer.
3. The value dereference (*) operator.
My understanding about 'address-of' / reference operator.
So say when I have a variable; int x = 5.
To get to the address of x, which is stored in the memory somewhere, I need to add the prefix & to the variable named x.
So when I typed &x, I can say it is now a variable that holds, the address of x, not the value.
So in conclusion, the address-of operator just 'assign' or give a copy of the memory of variable a to variable b, so that variable b can have access to its memory.
My understanding about how pointers are made.
So since we have the the reference of x, &x, that stores its address instead of the value, we can assign it to another variable.
Say, we assign it to variable y. Like this:
Since we store the address of x into y, we can say that y is a pointer, because y points to the variable whose reference it stores to, in this case, x.Code:
int y = &x; // this stores the address of x into y, making y a pointer
// that points to x.
My understanding about 'dereference' (*) operator.
y just store the address of x, but not the value. To get the value of x, one way is to simply use x. Another way is by using dereferencing operator, which is by just adding * before y, we can get the value of x, pointed by y:
int *y; //gives value of x since y stores a reference to x, or since x
//stores its address in y.
Is my understanding above right? Is that how they really relate to each other? Please correct the part where my conclusion is wrong and improve the idea of the terms above anywhere possible. Thanks.