指针,地址,相减结果为啥不是4,而是1

指针,地址,相减结果为什么不是4,而是1?

#include <stdio.h>
#include <windows.h>

int main(void)
{
int arr[] = {1, 2};
int* p = &arr[0];
int* q = &arr[1];
printf("%#x\n", p);
printf("%#x\n", q);
printf("%#x\n", q-p);
printf("%i\n", q-p);
    system("pause"); 
 
 return 0;



这是打印结果:
0x22ff40
0x22ff44
0x1
为啥q-p不是4,而是1?

------解决方案--------------------
因为地址相减的结果表示两个地址偏移了多少个元素。
------解决方案--------------------
其实相当于地址相减/sizeof(类型)   用来表示,俩指针间,间隔多少个类型个数。
------解决方案--------------------
楼主把int指针转换成char指针再减一下试试。
------解决方案--------------------
引用:
道理是这样的.
有官方的、有理有据的解释吗?


看下面的黑体字部分

C89

3.3.6 Additive operators
Syntax

    additive-expression:
        multiplicative-expression
        additive-expression + multiplicative-expression
        additive-expression - multiplicative-expression

Constraints

For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to an object type and the other shall have integral type. (Incrementing is equivalent to adding 1.)

For subtraction, one of the following shall hold:

    * both operands have arithmetic type;
    * both operands are pointers to qualified or unqualified versions of compatible object types; or
    * the left operand is a pointer to an object type and the right operand has integral type. (Decrementing is equivalent to subtracting 1.)

Semantics

If both operands have arithmetic type, the usual arithmetic conversions are performed on them.

The result of the binary + operator is the sum of the operands.

The result of the binary - operator is the difference resulting from the subtraction of the second operand from the first.

When an expression that has integral type is added to or subtracted from a pointer, the integral value is first multiplied by the size of the object pointed to. The result has the type of the pointer operand. If the pointer operand points to a member of an array object, and the array object is large enough, the result points to a member of the same array object, appropriately offset from the original member. Thus if P points to a member of an array object, the expression P+1 points to the next member of the array object. Unless both the pointer operand and the result point to a member of the same array object, or one past the last member of the array object, the behavior is undefined. Unless both the pointer operand and the result point to a member of the same array object, or the pointer operand points one past the last member of an array object and the result points to a member of the same array object, the behavior is undefined if the result is used as the operand of a unary * operator.