The first statement simply truncates the number at the decimal point. The n = static_cast<int>(x + 0.5) assignment gives the closest integer to x provided x is positive.

The result of the first and second are the same when, for x positive, the decimal portion is less than .5. Both assignments round down.

The result of the first and second are different when the decimal portion is greater than or equal to .5. Then the first assignment rounds down, the second one rounds up

For x negative, the first assignment still drops the fractional part. The second assignment, however, acts badly. It is always off by one from the closest integer. Consider the case where the fractional part is < 0.5, say -3.1. Adding 0.5 yields -2.6, and converting to an int yields -2, and not -3, the closest integer. Now assume the fractional part is > 0.5, say -3.9. Adding 0.5 yields -3.4, and converting to an int yields -3, and not -4, the closest integer.