Pointer comparison

后端 未结 2 930
礼貌的吻别
礼貌的吻别 2021-01-19 10:31

Do pointers in C and C++ support comparison operators (>, <, etc.) in standard?

I want to compare array positions to be precise.

相关标签:
2条回答
  • 2021-01-19 11:03

    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.

    0 讨论(0)
  • 2021-01-19 11:22

    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).

    0 讨论(0)
提交回复
热议问题