Subtracting two pointers giving unexpected result
问题 #include <stdio.h> int main() { int *p = 100; int *q = 92; printf("%d\n", p - q); //prints 2 } Shouldn't the output of above program be 8? Instead I get 2. 回答1: Undefined behavior aside, this is the behavior that you get with pointer arithmetic: when it is legal to subtract pointers, their difference represents the number of data items between the pointers. In case of int which on your system uses four bytes per int , the difference between pointers that are eight-bytes apart is (8 / 4) ,