Int v[10]; |
|
2分 |
百度搜索
指针算术 或者 指针运算 好好补课 |
3分 |
&v[x]的类型是int *,从3到5就2个整数,当然是2了,你要的8是 (char *)&v[5]-(char *)&v[3]
|
3分 | |
2分 |
是计算两个地址之间元素的个数,而不是字节的个数
|
3分 |
计算的结果是相差的元素位置(个数),不是具体字节数,因为一般关心的是位置
|
2分 |
2表示相差2个元素。
|
3分 |
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. |
2分 |
(char*)&v[5] – (char*)&v[3]结果会变成8
|
英语学的不好,翻译软件也不给力,自己百度查了下,还是没有得到我要的答案,我在问为什么结果要除4,只是因为结果8是字节差没有实际意思么?新手,也许问题很弱,但真的不懂 |
|
英语也是一门计算机语言的说。
|