My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program which show the basics of pointer

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int a=10;
 cout<<"value of a: "<<a<<endl;
 cout<<"address of a: "<<&a<<endl;
 cout<<"after operation p=&a "<<endl;
 int *p;
 p=&a;
 cout<<"add stores in p: "<<p<<endl;
 cout<<"add of p: "<<&p<<endl;
 cout<<"value of add stored in p: "<<*p<<endl;
 cout<<"after operation p++ "<<endl;
 p++;
 cout<<"p: "<<p<<endl;
 cout<<"&p: "<<&p<<endl;
 cout<<"*p: "<<*p<<endl;
 p+=10;
 cout<<"after operation p+=10 "<<endl;
 cout<<"p: "<<p<<endl;
 cout<<"&p: "<<&p<<endl;
 cout<<"*p: "<<*p<<endl<<endl<<endl<<endl<<endl;
 cout<<"after operating *p++"<<endl;
 *p++;
 cout<<"p: "<<p<<endl;
 cout<<"&p: "<<&p<<endl;
 cout<<"*p: "<<*p<<endl<<endl<<endl;
 cout<<"after operating ++*p"<<endl;
 ++*p;
 cout<<"p: "<<p<<endl;
 cout<<"&p: "<<&p<<endl;
 cout<<"*p: "<<*p<<endl<<endl<<endl<<endl;
 cout<<"after operating &p++ "<<endl;
 ++&p;                                              //give error
 cout<<"p: "<<p<<endl;
 cout<<"&p: "<<&p<<endl;
 cout<<"*p: "<<*p<<endl;


 getch();
 }

0 comments: