user-0 提问: 求解啊 代码 很短

回复:
user: user-1
content: 上面打印的全部是地址的值，两个相同类型的地址相减结果是偏移值，而不是实际的地址值的减法

user: user-2
content: 引用 5 楼 user-8 的回复:[quote=引用 4 楼 u012421456 的回复:] 你不加这个的话，system ("pause");能用吗？  "pause"只是system的实参， system是标准函数。 [/quote] 我也不太清楚，只知道曾经不用加“windows.h”可以用，但有时候又必须得加，不加就出错，不知道咋回事

user: user-3

user: user-4
content: mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VS\2052\vclang.chm::/html/_clang_subtraction_.289629.htm Subtraction (–) The subtraction operator (–) subtracts the second operand from the first. Both operands can be either integral or floating types, or one operand can be a pointer and the other an integer.    When two pointers are subtracted, the difference is converted to a signed integral value by dividing the difference by the size of a value of the type that the pointers address. The size of the integral value is defined by the type ptrdiff_t in the standard include file STDDEF.H. The result represents the number of memory positions of that type between the two addresses. The result is only guaranteed to be meaningful for two elements of the same array, as discussed in Pointer Arithmetic.   When an integer value is subtracted from a pointer value, the subtraction operator converts the integer value (i) by multiplying it by the size of the value that the pointer addresses. After conversion, the integer value represents i memory positions, where each position has the length specified by the pointer type. When the converted integer value is subtracted from the pointer value, the result is the memory address i positions before the original address. The new pointer points to a value of the type addressed by the original pointer value.

user: user-4
content: mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VS\2052\vclang.chm::/html/_clang_pointer_arithmetic.htm Pointer Arithmetic Additive operations involving a pointer and an integer give meaningful results only if the pointer operand addresses an array member and the integer value produces an offset within the bounds of the same array. When the integer value is converted to an address offset, the compiler assumes that only memory positions of the same size lie between the original address and the address plus the offset.  This assumption is valid for array members. By definition, an array is a series of values of the same type; its elements reside in contiguous memory locations. However, storage for any types except array elements is not guaranteed to be filled by the same type of identifiers. That is, blanks can appear between memory positions, even positions of the same type. Therefore, the results of adding to or subtracting from the addresses of any values but array elements are undefined.  Similarly, when two pointer values are subtracted, the conversion assumes that only values of the same type, with no blanks, lie between the addresses given by the operands.

user: user-5
content: 1.地址相减 == 地址偏移/每个元素所占空间（即代表偏移的元素个数） 2.你这个地方出现负数是因为：地址是无符号整数，所以这个地方%d输出产生了负数(实则为正).

user: user-6
content: 用%p打印p和q试试。

user: user-6
content: 用%p大约p和q试试。

user: user-0
content: 指针相减 难道不是地址相减吗  我是在windows下试的 用的 win-tc，这东西 不太好用，还是linux用的习惯 但是 差值 不对啊

user: user-7
content: 指向同一数组的两个指针相减，是两个指针存储值相减再除以所指向的类型大小

user: user-8
content: 引用 4 楼 u012421456 的回复:你不加这个的话，system ("pause");能用吗？  "pause"只是system的实参， system是标准函数。

user: user-2
content: 你不加这个的话，system ("pause");能用吗？

user: user-8
content: 引用 1 楼 u012421456 的回复:lz，你确定你的代码能运行？应该在上面加一个# include <windows.h>吧！ 最后运行结果我怎么得到的是这个 跟windows有啥关系。

user: user-8
content: 打印地址用%p,不要用%d 地址相减的意义是计算偏移量（中间有多多少个元素）：&a[2] - &a[0] 当然等于2

user: user-2
content: lz，你确定你的代码能运行？应该在上面加一个# include <windows.h>吧！ 最后运行结果我怎么得到的是这个