首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

指针数数运算中能使用数组最后一个元素的上一个元素的地址。这句话如何理解

2013-01-07 
【求助】指针数数运算中能使用数组最后一个元素的下一个元素的地址。这句话怎么理解?But the behavior is und

【求助】指针数数运算中能使用数组最后一个元素的下一个元素的地址。这句话怎么理解?
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

热点排行