Address of Operator (&):
& is sometimes referred to as the Referencing Operator. It’s a one-of-a-kind operator. The variable name that is used in conjunction with the Address of operator must be the name of a previously declared variable.
Using the & operator with a variable returns the variable’s address number.
Here’s an example of how the operator’s address can be used.
#include <iostream>
using namespace std;
int main()
{
int a = 10;
cout << "Address of variable a is " << &a << endl;
return 0;
}
Output:
0x61febc
The Indirection Operator
* is also known as the Dereferencing Operator. It is a unary operator. It takes an address as an argument and returns the content/container whose address is the argument.
Here’s one example of how to utilise the indirection operator.
#include <iostream>
using namespace std;
int main()
{
int a = 100;
cout << "Value of variable a stored at address " << &a << " is " << (*(&a)) << endl;
return 0;
}
Output
Value of variable a stored at address 0x61febc is 100