title: how to check integer overflow for 32 bit signed integer in c
body: <pre><code>int reverseNumber(int x){
  long k = x;
  long result=0;
  int negative=0;
  if (k &lt; 0)
  {
      negative = 1;
      k = 0 - k;
  }
  while (k != 0)
  {
      result = (result * 10) +( k % 10);
      k /= 10;
  
  }
  if (result &gt;INT_MAX)
      return 0;
  else
  {
      if (negative == 1)
          return (0-(int)result);
      else
          return (int)result;
  }
  }
  </code></pre>
  
  <p>this is the function code for reversing a 32 bit integer and to check integer overflow condition.The code has to return 0 for the overflow case otherwise the reversed number.For the input 2147483647(INT_MAX) i am still getting the output -1126087180 which actually should be a zero.Please can anyone help with this.
                   thank you</p>