Re: Subtracting Two Pointers
>> 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'.)
"int" takes 2 bytes so (2000-1000)/2 = 500
"char" takes 1 byte so (2000-1000)/1 = 1000
and so on for float (4 bytes) and double (8 bytes)
>>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'.
*p = 1000; // value pointed to by p is 1000
p = (int *)1000; //p points to address 1000