Difficulty: Easy
Correct Answer: Syntax errors
Explanation:
Introduction / Context:
Compilers analyze source code to transform it into object code. Along the way, they validate program structure. Understanding what a compiler can and cannot detect helps developers interpret error messages and design tests.
Given Data / Assumptions:
Concept / Approach:
All compilers detect syntax errors because parsing requires the program to adhere to grammar rules. Many compilers also detect numerous semantic errors (e.g., type mismatches, undeclared identifiers). Logical errors (algorithmic mistakes) typically compile fine but produce wrong results at runtime. The safest, universally correct answer is that compilers detect syntax errors.
Step-by-Step Solution:
Verification / Alternative check:
Parsing fails immediately on grammar violations; compilers emit errors such as “expected ;” or “unexpected token.”
Why Other Options Are Wrong:
Common Pitfalls:
Assuming all meaning-related mistakes are caught at compile time; languages with dynamic typing defer many checks to runtime.
Final Answer:
Syntax errors
Discussion & Comments