Possible Duplicate:
Why do these two pointer subtractions give different results?
char arr[] = "stackoverflow";
char *p1 = arr;
char *p2 = arr + 3;
printf("%d", (int*)p2 - (int*)p1);
it’s answer is 0..Can you explain why is it so ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
p2 - p1is< sizeof (int). So(int *) p2 - (int *) p1 == 0, the number ofintelements between the two pointers.