Difficulty: Easy
Correct Answer: Error: Statement missing
Explanation:
Introduction / Context:
This item checks attention to C statement syntax. Each expression statement must end with a semicolon, including calls to printf
. Missing terminators commonly cause confusing parser errors near subsequent lines.
Given Data / Assumptions:
x
and y
.printf
lacks a trailing semicolon.
Concept / Approach:
In C, a function call used as a statement is an expression statement and must end with ;
. Omitting it results in a syntax error, often reported as “expected ‘;’ before ‘return’” or “statement missing”. The logic of comparisons is otherwise fine.
Step-by-Step Solution:
Locate printf("x is less than y\n")
→ no semicolon.Parser therefore merges the next line into the same statement and fails.Add ;
to fix: printf("x is less than y\n");
Verification / Alternative check:
Recompile after adding the semicolon; the program will run and print exactly one of the three messages based on values.
Why Other Options Are Wrong:
Expression syntax is vague; the specific, conventional diagnostic is a missing statement terminator. Lvalue/Rvalue required do not apply to a function call.
Common Pitfalls:
Forgetting semicolons on single-line conditionals; misreading the compiler’s error location when it points to return
or the line after the offending call.
Final Answer:
Error: Statement missing
Discussion & Comments