C++ Going Over INT_MAX?

  c++, integer

Suppose I have:

int x=INT_MAX-1;
if (x+2 > INT_MAX)
    cout << "ERROR";
  1. Will this case undefined behavior?

  2. Where the compiler will save the temporary result of x+2, will it use int by default, double by default, the same type of x or it will be smart enough to choose something big enough?

Source: Windows Questions C++

LEAVE A COMMENT