Re: pointer arithmetic




<barikat@xxxxxxxxx> wrote in message
news:1151077831.567780.241310@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
int a[5];
int *Ptr1, *Ptr2;

Ptr1 = a;
Ptr1++;
Ptr2 = a;

printf("Ptr1 : %p\n", Ptr1);
printf("Ptr2 : %p\n\n", Ptr2);

Ptr1 = Ptr1 - Ptr2;

---------------------
Ptr1 : 0012FF6C
Ptr2 : 0012FF68

Ptr1 : 00000001
Ptr2 : 0012FF68
----------------------

i couldnt understand, Ptr1 = Ptr1 - Ptr2; line is a pointer arithmetic,
and Ptr1 should be 0012FF6C, because Ptr1 is a[1] and Ptr2 is a[0]
a[1] - a[0] should be a[1] so 0012FF6C
probably i am wrong but i wanted to ask :)

If you live at 301 Elm Street and your friend lives at 303 Elm Street and
houses on your side of the street are odd-numbered, how many houses away
from you does your friend live?

N


.



Relevant Pages