A simple Pointer Example in C++

A pointer means memory address of an object. A reference is an alias for an object. In order to view the function of a pointer, lets see the example below :
 #include <iostream.h>
#include <conio.h>

void main(){

int a=35;
int *pa,*qa;
pa=&a;
qa=pa;

cout<<"Value of a      : "<<a<<endl;
cout<<"Address a     : "<<&a<<endl;
cout<<"Value of *pa    : "<<*pa<<endl;
cout<<"Value of pa     : "<<pa<<endl;
cout<<"value of *qa    : "<<*qa<<endl;
cout<<"Value of qa     : "<<qa<<endl;
getch();
}
and the other example :

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

void main(){
int a=35;
int *pa;
pa=&a;

cout<<"Value of a : "<<a<<endl;
cout<<"Value of pa : "<<*pa<<endl;

*pa=100;

cout<<"Value of a: " <<a<<endl;
cout<<"Value of pa: "<<*pa<<endl;

getch();

}
and this is how to using pointer in an array structure :
#include <iostream.h>
#include <conio.h>

void main(){
int a[7]={17,68,99,56,45,65,78};
int *pa;
pa=a;
cout<<"pa : "<<*pa;
getch();
Previous
Next Post »