Wednesday, 21 December 2011

What are Pointers?

A pointer provides a way of accessing a variable without referring to the variable directly.
The mechanism used for this is the address of variable. The address act as an intermediate between the variable  and the program accessing it.
Let's have a look at the following example:


#include<stdio.h>
#include<conio.h>
void main()
{
   int *p, q;   //pointer variable always initialize with an *
     q = 100;   //assigning value to q 
     p = &q;    //inserting the address of q into p
       printf("%d",*p);  //see the description below
   getch();     //exit on key press                                                         
}

In the above program, the value of q (i.e. 100) is shown through the pointer variable p (i.e. *p). You can easily see in the picture above. First, store 100 the q variable and then the address of q (i.e. 1312) is given to pointer variable p and at last the value of q is print through pointer variable (*p).

If you still have any problem or confusion, you can contact me... 

0 comments:

Post a Comment