C ++:指针运算 [英] C++: Pointer Arithmetic
问题描述
我在读指针运算了一下,我来到两件事我不明白也不知道它的使用
I was reading a bit in Pointer Arithmetic, and I came upon 2 things I couldn't understand neither know it's use
address_expression - address_expression
和也
address_expression > address_expression
有人可以解释他们对我来说,他们如何工作和使用它们时。
Can someone please explain them to me, how do they work and when they are used.
编辑:
我的意思是说你是他们所生产什么,如果我只是把两个地址和减去它们
What I meant to say is what do they produce if I just take two addresses and subtract them
如果我拿两个地址并进行比较的结果是什么或比较基于
And If I take two addresses and compare them what is the result or comparing based upon
编辑:
我现在明白减去地址,但地址的比较我还是不明白这一点的结果。
I now understand the result of subtracting addresses, but comparing addresses I still don't get it.
据我所知,1&2,但如何是一个地址比另一个更大,什么是他们在
I understand that 1<2, but how is an address greater than another one and what are they compared upon
推荐答案
指针减法得到的数组元素的相同类型的两个指针之间的数。
Pointer substraction yields the number of array elements between two pointers of the same type.
例如,
int buf[10] = /* initializer here */;
&buf[10] - &buf[0]; // yields 10, the difference is 10 elements
指针比较。例如,对于&GT;
关系运算符:在&GT;
操作收益率 1
如果在左侧的尖数组元素或结构成员是在右边的尖数组元素或结构成员后它产生 0
,否则。记住数组和结构是有序的序列。
Pointer comparison. For example, for the >
relational operator: the >
operation yields 1
if the pointed array element or structure member on the left hand side is after the pointed array element or structure member on the right hand side and it yields 0
otherwise. Remember arrays and structures are ordered sequences.
&buf[10] > &buf[0]; // 1, &buf[10] element is after &buf[0] element
这篇关于C ++:指针运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!