title: Exact meaning of == in C
body: <p>I am a bit confused about the exact meaning of operator <code>==</code> in C.</p>
  <p>Does it compare mathematical values variables represent (depending on their types) or the bit patterns behind the variables? Specifically:</p>
  <pre><code>int x = 0x80000000;
  unsigned y = x;
  x==y // true
  </code></pre>
  <p>So despite the fact that x is a large negative value and y is a large positive they are equal (I guess because they have the same bit pattern).</p>
  <pre><code>int64_t x = 0x8000000000000000;
  int y = x;
  x==y // false
  </code></pre>
  <p>Here it does not matter that the first (least significant) 32 bits in x and y are the same. So it looks like in this case C looks at the values represented by the variables.</p>
  <p>What are the official rules and is there an authoritative reference for this (have not found anything useful on this in K&amp;R)?</p>
  <p>I have used <code>gcc</code> compiler for the above examples.</p>