In C++ (default arguments and pre-increment effects), evaluate the function call and compute the exact integer result.
#include
long CuriousTabFunction(int x, int y = 5, float z = 5)
{
return (++x * ++y + (int)++z);
}
int main()
{
cout << CuriousTabFunction(20, 10);
return 0;
}
-
A237
-
B242
-
C240
-
D35
-
EThe program will report error on compilation.
Answer
Correct Answer: 237
Explanation
Introduction / Context: This checks your fluency with default parameters, pre-increment semantics, and casts from floating point to integer in C++. The order of operations is explicit because increments occur on local parameters before multiplication and addition in a straightforward expression.
Given Data / Assumptions:
- Call:
CuriousTabFunction(20, 10)→x=20,y=10,z=5(default forz). - Expression:
++x * ++y + (int)++z.
Concept / Approach: Pre-increment increases the operand and yields the incremented value. Casting a float to int truncates toward zero. Multiplication and addition then combine these updated values deterministically (no sequencing pitfalls here because the operands do not alias the same object).
Step-by-Step Solution:
++x → 21 ++y → 11 ++z → 6.0, cast to int → 6 Compute: 21 * 11 + 6 = 231 + 6 = 237Verification / Alternative check: Evaluating on paper or in a small REPL reproduces the same deterministic steps since there is no undefined behavior in this expression.
Why Other Options Are Wrong:
- 242 or 240: Miscalculations of either the product or casted addend.
- 35: Treats increments as if unused or misapplies operator precedence.
- Compilation error: The code is well-formed under classic headers.
Common Pitfalls: Forgetting that ++z happens before the cast and truncation, or mixing up pre- vs post-increment results.
Final Answer: 237