读书人

指针数数运算中能使用数组最后一个元素

发布时间: 2013-01-07 10:02:24 作者: rapoo

【求助】指针数数运算中能使用数组最后一个元素的下一个元素的地址。这句话怎么理解?
But the behavior is undefined for arithmetic or comparisons with pointers that do not point to members of the same array. (There is one exception: the address of the first element past the end of an array can be used in pointer arithmetic.)

括号中说的例外,具体指的是什么?

[解决办法]
arr[3]:
*p;*q;
ADDRESS:
0x0001: a[0]<---p
0x0002: a[1]
0x0003: a[2]
0x0004: 0xFF<---q

q is the point to the first address past array arr.
it is meanful to do arithmetic with p and q.
e.g.: q-p is the arr length

读书人网 >C语言

热点推荐