Difficulty: Easy
Correct Answer: The program will print the output 24.
Explanation:
Introduction / Context: This question checks your understanding of default function arguments, loop bounds, and how an off-by-one choice in the loop makes the routine compute a product up to x - 1 rather than x. It also reinforces that the loop in main executes exactly once and calls the function with its default parameter value.
Given Data / Assumptions:
Concept / Approach: Because the call uses the default, x is 5. The function multiplies numbers from 1 through 4 (not 5). That computes 1 * 2 * 3 * 4 = 24. It then returns this value, which is printed by cout from main, followed by a newline.
Step-by-Step Solution:
In main: the loop runs exactly once and calls FactFinder() → x = 5.Check x < 2 → false; proceed to compute.Initialize fact = 1.Multiply for i = 1..4: fact = 11 → 1; then 12 → 2; then 23 → 6; then 64 → 24.Return 24; cout prints 24.Verification / Alternative check: If the loop were i <= x instead of i <= x - 1, the result would be 120 for x = 5. The present code intentionally stops early.
Why Other Options Are Wrong:
Common Pitfalls: Confusing default-argument usage, assuming factorial(x) instead of factorial(x - 1), or thinking the for loop in main runs multiple times. Also, overlooking that the code prints once because the loop bound is i <= 0.
Final Answer: The program will print the output 24.
Discussion & Comments