Saturday, October 12, 2013

Pointers....

What is pointer???

Definition:

                 A pointer is a special kind of variable in C and C++ that holds the address of another variable.
 
C language use a lot of pointers...:
        there are some reasons.....
  1. It is the only way to express some computations.
  2. It produces compact and efficient code.
  3. It provides a very powerful tool.
C uses pointers explicitly with:

  1.     Arrays,
  2.     Structures,
  3.     Functions.
     
Now you see the very simple example of Pointer ...after seeing this you will understand about pointers......


#include"stdafx.h"

#include"iostream"

#include"conio.h"

usingnamespacestd;

 

int main()

{      /* Use of pointors*/

       /*pointers only saves Adresses*/

       int n=10;

       int *a;      /* *a is pointer*/

       a=&n;

       cout<<"Adress of n in pointer a="<<a<<endl;

       cout<<"Value at adress n="<<*a<<endl;

       cout<<"Adress of pointer a="<<&a<<endl;

       cout<<"Increment in value at a="<<*a+1<<endl;

       cout<<"increment in adress="<<a++;

       getch();

       return 0;

}

Output of this program is>>>

Adress of n in pointer a=0012FF28
Value at address n=10
Adress of pointer a=))12FF1C
Increment in value at a=11
Increment in address=0012FF28

Hope so you will enjoy it......

No comments:

Post a Comment