Wednesday, August 31, 2011

Pointer

pointer is a variable that contains the memory address as a value, different from ordinary variable that contains the specified value. In other words, the pointer contains the address of the variable that has a certain value. Thus, there are variables that directly points to a specific value and a variable that indirectly (a variable pointer) points to the value.

int * countPtr, count;

pointer operator
address operator (denoted as &) is a unary operator that returns the address of the operator. as an example, assume the following declaration:

int y = 5
int * yPtr;


examples of program code pointer : (....)


#pragma argsused
#include <iostream.h>
int main(){
   void *z;
   int p;
   long x;
   double r;

   z=&p;
   p=10;
   cout<<"value p:"<<p<<endl;
   cout<<"value z:"<<z<<endl;
   //cout<<"value *z :"<<*z<<endl;
   cout<<"value &p :"<<&p<<endl;
   cout<<"\n";

   z=&x;
   x=20;
   cout<<"value x:"<<x<<endl;
   //cout<<"value *z :"<<*z<<endl;
   cout<<"value z:"<<z<<endl;
   cout<<"value &x :"<<&x<<endl;
   cout<<"\n";

   z=&r;
   r=30;
   cout<<"value r:"<<r<<endl;
   //cout<<"value *z :"<<*z<<endl;
   cout<<"value z:"<<z<<endl;
   cout<<"value &r :"<<&r<<endl;
   cout<<"\n";

   cin>>x;

        return 0;
}




source : http://web.ipb.ac.id/~julio/webaku/isi/kom202/notes/7.pdf

0 comments:

Template by : wanto arwan-programing.blogspot.com