title: C Integer Behavior: Dividing by Zero
body: <p>I recently decided to satisfy a long time curiosity of mine. <b>What happens when you divide by zero in C?</b> I had always simply avoided this situation with logic, but was curious how a language like C, which cannot throw a catchable exception, handles this situation. </p>
  
  <p>Here was my very simple test (compiled with GCC on Windows 10):</p>
  
  <pre><code>int main()
  {
      double test1 = 1.0/0.0;
      printf( "%f", test1 );
      int test2 = 1/0;
      printf( "%d", test2 );
  }
  </code></pre>
  
  <p>The operation done with the <code>double</code> types gave me a lovely little indication that the result was not a number: <code>1.#INF00</code>. All's fine so far..</p>
  
  <p>However, when performing a divide by zero with <code>int</code> types, the program, less than eloquently, "stopped working." I'm running this on Windows, so I was alerted with that lovely dialog.</p>
  
  <p><b>I am curious about this behavior.</b> Why is crashing the program the choosen solution for an integer division by zero? Is there really no other solution, say akin to the <code>double</code> way, to handle division by zero? Is this the same behavior on every compiler, or just GCC? </p>