Tuesday, 9 June 2015

Program to illustrate the operations that can be performed on pointers


Code for Program to illustrate the operations that can be performed on pointers in C++ Programming



 
#include<iostream.h>
 #include<conio.h>


 main()
    {
       clrscr();

       int i=5;
       int *j;

       j=&i;

       float f=10.5;
       float *g;

       g=&f;

       char c='q';
       char *d;

       d=&c;

       cout<<"\n --------- values of variables ---------\n"<<endl;
       cout<<"value of i = "<<i<<endl;
       cout<<"value of f = "<<f<<endl;
       cout<<"value of c = "<<c<<endl;

       getch();

       cout<<"\n --------- addresses of variables --------\n"<<endl;
       cout<<"address of i = "<<&i<<endl;
       cout<<"address of f = "<<&f<<endl;
       cout<<"address of c = "<<&c<<endl;

       getch();

       cout<<"\n ---------- values of pointers ----------\n"<<endl;
       cout<<"value of j = "<<j<<endl;
       cout<<"value of g = "<<g<<endl;
       cout<<"value of d = "<<d<<endl;

       getch();

       j++;
       g++;
       d++;

       cout<<"\n ---------- values of pointers after modification --------\n"<<endl;

       cout<<" j++"<<endl;
       cout<<"value of j = "<<j<<endl;
       cout<<" g++"<<endl;
       cout<<"values of g = "<<g<<endl;
       cout<<" d++"<<endl;
       cout<<"values of d = "<<d<<endl;

       cout<<"\n --------- values contained by pointers --------\n"<<endl;
       cout<<"value of *j = "<<*j<<endl;
       cout<<"value of *g = "<<*g<<endl;
       cout<<"value of *d = "<<*d<<endl;

       getch();
       return 0;
    }



 



 

No comments:

Post a Comment