Pointers Execution

I am not able to understand the working of the program. Kindly explain the execution of pointers
int *p,*q;
p=(int *)1000;
q=(int *)2000;
printf("%d",(q-p));

In this Block of code , there is static allocation of pointers to numbers which are type cast to pointers . so , these numbers are converted into hexadecimal values as addresses in C++ are of type Hexadecimal.
So if you try this .

cout<<(int *)1000;

this will give output as 0x3e8 . Subtracting two addresses gives an integer value.

1 Like