C Language - Pointer - Pointer


This statement instructs the system to reserve a 2-byte memory location and puts the value 84 in that location. Assume that a system allocates memory location 1001 for num. diagrammatically, it can be shown as.


It is a special variable which stored address of another variable.

Declaration of pointer We can declare pointer similarly as we declared any variable in C.
Syntax:      *pointervariable;
	    Int  *iptr;
	    float  *fptr;
	    char  *cptr;
This tells the compiler three things about the variable iptr.
1. The asterisk (*) tells that the variable iptr is a pointer variable.
2. iptr needs a memory location.
3. iptr points to a variable of type data type.
Declaration style We can declare pointer using three ways.
Int*   iptr;
Int  * iptr;
Int     *iptr;
Pointer assignment
We can assign pointer variable as similar as normal assignment in c.
Pointer_variable = &variable;
int a= 20;
int  *iptr;
iptr = &a;   /* pointer assignment */

(& )means address of
EX: WAP to print address of variable
void main()
 int age =30;
 float sal = 1500.50;
 printf("Address of age=%u\n",&age);
 printf("Address of salary=%u\n",&sal);