Address Operator in C Programming
- It is Denoted by ‘&’
- When used as a prefix to a variable name ‘&’ operator gives the address of that variable.
Example :
&n - Gives address on n
Invalid Use of Address Operator
- We cannot use Address operator for Accessing Address of Literals.
- Only Variables have Address associated with them.
&75
- (a+b) will evaluate addition of Values present in variables.
- Output of (a+b) is nothing but Literal , so we cannot use Address operator
&(a+b)
- Again ‘a’ is Character Literal, so we cannot use Address operator.
&('a')How Address Operator works ?
#include<stdio.h> void main() { int a = 10; printf("\nValue of n is : %d",n); printf("\nValue of &n is : %u",&n); }
Output :
Value of n is : 10 Value of &n is : 1002
Visual Understanding :
After declaration memory map will be like this -
int i = 5; int *ptr;

after Assigning the address of variable to pointer , i.e after the execution of this statement -
ptr = &i;


