Difficulty: Easy
Correct Answer: 5
Explanation:
Introduction / Context:
This checks operator precedence and side effects when mixing integer modulo with floating-point arithmetic and a pre-decrement on a float parameter.
Given Data / Assumptions:
CuriousTabFunction(20, 2.0f, 5.0f)
.a % 20 + c * --b
.a
is int; b
and c
are float.
Concept / Approach:--b
executes first on the right-hand factor, then multiplication, then the integer result of a % 20
is promoted and added.
Step-by-Step Solution:
1) Compute a % 20
: since a=20
, remainder is 0.2) Pre-decrement b
: from 2.0 to 1.0.3) Multiply: c * --b = 5.0 * 1.0 = 5.0
.4) Add: 0 + 5.0 = 5.0
. Stream insertion prints 5
(implementation may omit trailing .0
).
Verification / Alternative check:
Print intermediate values or rewrite as float r = a % 20; r += c * (--b);
and display r
.
Why Other Options Are Wrong:
0 ignores the c * --b
term; 100 and -5 come from misapplying decrement or precedence; “None” is unnecessary since 5 fits exactly.
Common Pitfalls:
Using post-decrement by mistake or assuming a % 20
affects b
.
Final Answer:
5
Discussion & Comments