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
Edit: I now understand the result of subtracting addresses, but comparing addresses I still don’t get it.
I understand that 1<2, but how is an address greater than another one and what are they compared upon
Pointer subtraction yields the number of array elements between two pointers of the same type.
int buf = /* initializer here */; &buf - &buf; // yields 10, the difference is 10 elements
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 > &buf; // 1, &buf element is after &buf element