Data can be stored using variables, and variables store data in memory.
But what if we want to access that memory directly? We can use a reference operator &.
char letter = 'A';
cout << &letter;The reference operator returns the exact memory address where the data in a specific variable is stored.
In short, it takes any variable, then gives where in memory is the data inside it is stored.
For example, if we output them:
char letter = 'A';
char *address = &letter;
cout << letter << endl; // Outputs 'A'
cout << address << endl; // Outputs a memory address, like 0x1000A pointer, also known as a dereference operator, takes a memory address and returns the exact data stored in that address.
So if we output *address, it should return 'A' as that was the value stored in that specific address.
To store a memory address of a variable var, we often store it in a pointer:
dataType *address = &var;The data type of *address* should be the same as the data type of dataType.