Correct but probably useless answer: p - q is equal to (1000 - 2000) / (sizeof int). For most C compiles, sizeof int is 4.
Potentially more useful answer: the effect of typecasts like (int*) 1000 is undefined. That code creates a pointer to an int at address 1000. That address is probably invalid. To create a pointer to an int with value 1000, write this:
int i = 1000; int *p = &i;
Now p points to i, and *p, the value pointed to by p, is 1000.
Here is some correct code that may say what you meant:
int main() { int i = 1000; int j = 2000; int *p = &i; int *q = &j; printf("i = %d *p = %d\n", i, *p); printf("j = %d *q = %d\n", j, *q); printf("*p - *q = %d\n", *p - *q); }
%dformat specifier invokes undefined behaviour. You can printvoid*with the%pformat specifier,printf("%p ", (void*)p);, or you can cast the pointer to an integer type before printing,printf("%" PRIdPTR " ", (intptr_t)p);. For the pointer difference,printf("%td ", (p-q));.