Pointer Variable = (Pointer Variable 1 – Pointer Variable 2) / Base Type

#include<iostream.h>
#include<conio.h>
void main()
{
                int a,b,c,*ptr1,*ptr2;
                clrscr();
                ptr1=&a;
                ptr2=&b;
                cout<<"Value of ptr1 = "<<(unsigned)ptr1<<endl;
                cout<<"Value of ptr2 = "<<(unsigned)ptr2<<endl;
                c=ptr1-ptr2;
                cout<<"Value of C = "<<(unsigned)c<<endl;
                getch();
}

106

Advertisements