C++ defaults and pre-decrement with mixed integer/float args: evaluate the expression a % 20 + c * --b for the provided call.\n\n#include<iostream.h>\nclass CuriousTabSample{\npublic:\n int a; float b;\n void CuriousTabFunction(int a, float b, float c=100.0f){ cout << a % 20 + c * --b; }\n};\nint main(){ CuriousTabSample obj; obj.CuriousTabFunction(20, 2.000000f, 5.0f); }

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:

  • Call: CuriousTabFunction(20, 2.0f, 5.0f).
  • Expression: 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

More Questions from Functions

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion