Difficulty: Easy
Correct Answer: The program will report compile time error.
Explanation:
Introduction / Context:
In C++, the % (remainder) operator is defined only for integral types. Attempting to apply it to floating-point operands is ill-formed. This snippet intentionally uses % with float values to provoke a compiler diagnostic.
Given Data / Assumptions:
Concept / Approach:
Both operands to % must be integral. Since ++x and --y are still floats, there is no valid operator% overload, and the code fails to compile with an error similar to “invalid operands to binary %”.
Step-by-Step Solution:
Verification / Alternative check:
Changing the members to int (and passing integer literals) would allow % and yield a value. Alternatively, use fmod from
Why Other Options Are Wrong:
Common Pitfalls:
Assuming % behaves like mathematical modulus for floats, or forgetting to use fmod for double/float types.
Final Answer:
The program will report compile time error.
Discussion & Comments