Comparing Pointer

S

sebastien.fricker

Does anybody know if it is allowed to compare pointer using the
operators '<', '<=', '>' or '>='?
 
R

Richard Bos

Does anybody know if it is allowed to compare pointer using the
operators '<', '<=', '>' or '>='?

Yes, but with limitations. You're allowed to compare any two valid or
=, though, there is the additional demand that they must point within
the same object (array, struct, union, etc.). If not, the behaviour is
undefined. That also means that you can't compare to a null pointer
(constant) using < or >.

Richard

[1] Or pointers to void, or pointers to qualified versions of compatible
types, or null pointer constants.
 
K

Keith Thompson

Does anybody know if it is allowed to compare pointer using the
operators '<', '<=', '>' or '>='?

If your textbook doesn't answer that question, get a better one. I
recommend K&R2 (Kernighan & Ritchie, _The C Programming Language_, 2nd
Edition).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top