Reputation: 93
Do pointers in C and C++ support comparison operators (>
, <
, etc.) in standard?
I want to compare array positions to be precise.
Upvotes: 4
Views: 5184
Reputation: 1316
Yes, they can be compared.
For example, see "Relational Operators" in standards for further information, 6.5.8 in C99, and 5.9 in old draft of C++ (2006-11).
Upvotes: 1
Reputation: 35925
In a contiguous array comparing memory offsets (pointers) is OK. If your array is implemented as a linked list (for example) the nodes could be all over memory so pointer comparison is nonsensical.
Upvotes: 12