title: Is pointer comparison undefined or unspecified behavior in C++?
body: <p>The C++ Programming Language 3rd edition by Stroustrup says that,</p>
  
  <blockquote>
    <p>Subtraction of pointers is defined only when both pointers point to
    elements of the same array (although the language has no fast way of
    ensuring that is the case). When subtracting one pointer from another,
    the result is the number of array elements between the two pointers
    (an integer). One can add an integer to a pointer or subtract an
    integer from a pointer; in both cases, the result is a pointer value.
    <strong>If that value does not point to an element of the same array as the
    original pointer or one beyond, the result of using that value is
    undefined.</strong></p>
  </blockquote>
  
  <p>For example:</p>
  
  <pre><code>void f ()
  {
      int v1 [10];
      int v2 [10];
      int i1 = &amp;v1[5] - &amp;v1[3];   // i1 = 2
      int i2 = &amp;v1[5] - &amp;v2[3];   // result undefined
  }
  </code></pre>
  
  <p>I was reading about <a href="https://en.wikipedia.org/wiki/Unspecified_behavior">unspecified behavior</a> on Wikipedia. It says that</p>
  
  <p>In C and C++, the comparison of pointers to objects is only strictly defined if the pointers point to members of the same object, or elements of the same array.</p>
  
  <p>Example:</p>
  
  <pre><code>int main(void)
  {
    int a = 0;
    int b = 0;
    return &amp;a &lt; &amp;b; /* unspecified behavior in C++, undefined in C */
  }
  </code></pre>
  
  <p>So, I am confused. Which one is correct? Wikipedia or Stroustrup's book? What C++ standard says about this?</p>
  
  <p>Correct me If I am misunderstanding something.</p>