Pointers are one of the hardest parts of programming to understand. But they are very useful.
When programming with pointers, we use two operators: reference operator (&) and dereference operator (*).
We use the reference operator to see the address where a variable is stored, and the dereference operator is to see the value of a variable.
Example:
int a = 10; int *ptr = &a; cout << ptr << endl; //Will print the address of a in hex cout << *ptr << endl; //Will print the value of a (10) //ptr = a; This is wrong
Now, the addres of the variable a is stored in ptr, this means that ptr shows on a. According to this we can change the value of a using ptr.
See this example:
*ptr = 20; cout << a << endl; //Will print 20

As you see on the picture, the variable a is stored on the memory location 0002 with its value 10, and ptr is stored on the memory location 0005 and its value is the address of variable a (0002). This explains the above example.
In one the next articles we will explain using pointers with arrays, so stay tuned.







