Result of some pointer comparisons

suggest change

If two pointers are compared using \<, \>, <=, or >=, the result is unspecified in the following cases:

int x;
  int y;
  const bool b1 = &x < &y;            // unspecified
  int a[10];
  const bool b2 = &a[0] < &a[1];      // true
  const bool b3 = &a[0] < &x;         // unspecified
  const bool b4 = (a + 9) < (a + 10); // true
                                      // note: a+10 points past the end of the array
class A {
  public:
    int x;
    int y;
    bool f1() { return &x < &y; } // true; x comes before y
    bool f2() { return &x < &z; } // unspecified
  private:
    int z;
};

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents