Thursday, January 12, 2012

What would be the result of the expression -6/5?

The ANSI C standard says that the result is "implementation defined." This means that ANSI C has no hard and fast rule, therefore, the result depends on the compiler that you use. Check your compiler; it should give either -1 or -2 as a result.

Note that the "correct" answer is -1.2. The compiler therefore has a choice of rounding up or down.

No comments:

Post a Comment