Here is a small piece of code.
When I compile and run it, I get the answer as '500'. Is it because, when you subtract two pointers, you get the number of units of [data type] that lies in between them? (I tried using char. Then the output was '1000'. For float, it was '250', and for double, it was '125'.)Code:#include <stdio.h> int main(void) { int *p, *q; p = (int *) 1000; q = (int *) 2000; printf("%d", q - p); return 0; }
I have one more question. Why is the type cast (int *) necessary? When I do without the cast, I get a warning: 'Nonportable pointer conversion'. What does that mean? Although the warning comes, the program runs just fine.
Please help.
I use Turbo C++ 3.0.