Operations on Pointers
Address of Operator (&)
- It is a unary operator.
- Operand must be the name of an already defined variable.
- & operator gives the address number of the variable.
- & is also known as the “Referencing Operator”.
Here’s one example to demonstrate the use of the address of the operator.
#include <stdio.h> int main() { int a = 100; printf("%d\n", a); printf("Address of variable a is %d", &a); return 0; }
Output:
100 Address of variable a is 6422220
Indirection Operator (*)
- * is an indirection operator.
- It is also known as the “Dereferencing Operator”.
- It is also a unary operator.
- It takes an address as an argument.
- * returns the content/container whose address is its argument.
Here’s one example to demonstrate the use of the indirection operator.
#include <stdio.h> int main() { int a = 100; printf("Value of variable a stored at address %d is %d.", &a, *(&a)); return 0; }
Output:
Value of variable a stored at address 6422220 is 100.