An example to illustrate Pointer

#include <iostream.h> #include <conio.h>
void main( )
{
int x=3;
int *ptr;
clrscr();
ptr = &x;
cout<<”Address of x = “<< &x<<”\n”;
cout<<”Address in ptr = “<< ptr<<”\n”;
cout<<”Address of pointer = “<< &ptr<<”\n”
cout<<”Value in x = “<< x<<”\n”;
cout<<”Value at address of x = “<< *(&x)<<”\n”;
cout<<”Value at pointer = “<< *ptr<<”\n”;
getch();
}
Output :
Address of x = 64482
Address in ptr = 64482
Address of pointer = 64484
Value in x = 3
Value at address of x = 3
Value at pointer = 3

0 comments: