Pointer : Address Operator (&) in C Programming

March 18, 2012 No Comments » Hits : 362





Address Operator in C Programming

  1. It is Denoted by ‘&’
  2. 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;

Before Assigning Address to Variable Pointer
after Assigning the address of variable to pointer , i.e after the execution of this statement -

ptr = &i;

After Assigning Address of Variable to Pointer

Incoming search terms: