Symbol |
Name |
Description |
& (ampersand sign) |
address of operator |
determines the address of a variable |
* (asterisk sign) |
indirection operator |
accesses the value at the address |
Address of Operator:
The address of operator ‘&’ returns the address of a variable.
We need to use %u to display the address of a variable.
Example:
#include <stdio.h>
int main(){
int i=2;
printf(“\nAddress of i=%u”,&i);
printf(“\nValue of i=%d”,i);
return 0;
}
Output:
Address of i=62254
Value of i=2
The expression &i returns the address of the variable i, which in this case is 62254. Since 62254 represents an address, there is no sign associated with it. Hence it is printed out using %u, which is a format specifier for printing an unsigned integer.
The other pointer operator available in C is ‘*’,which is known as the ‘value at address’ operator. It gives the value stored at a particular address.The ‘value at address’ operator is also called ‘indirection’ operator.
#include <stdio.h>
int main(){
int i=2;
printf(“\nAddress of i=%u”,&i);
printf(“\nValue of i=%d”,i);
printf(“\nValue of i=%d”,*(&i));
return 0;
}
Output:
Address of i = 62254
Value of i = 2
Value of i = 2
Printing the value of *(&i) is the same as printing the value of i.