Hello,
This is just a little summary of pointers that I wrote, I would appreciate it if you could verify that it is correct and maybe add a little more if there's something else you think I should add.
Pointers
When initialising, an asterisk means that it is a pointer. The data type (‘int’, ‘byte’ etc.) means that it will point to that data type. For example, this just initialises a pointer called ptr which points to an int, but doesn't actually point to any address yet.
int *ptr;
Saying
int *ptr = 50;
means that you initialise a pointer to point to address no. 50. You would usually give the address of a variable here (using ‘&’) It is the same as saying:
int *ptr;
ptr = 50;
When running, * means value stored at the address which it points to (the real info you want). So in this case, the value at the address is set to 50. Recognise the different uses of the asterisk when initialising the pointer and when using while the rest of the program is running.
*ptr = 50;
Just using ptr (no asterisk) will give you the address, that it is pointing to, not the value stored there.
Saying
int x = 10;
int *ptr = &x;
Means that ptr now points to x. *ptr would now return 10 (the same as just saying x) and ptr would return the memory address of x (the same as saying &x).
And, if I'm right with all this, what's the point of using pointers (pun not intended)? Why not just use the variable itself and its address if you need to (x and &x instead of *ptr and ptr)?
Thanks.