Error Types in Compilation (Lexical, Syntax, Semantic) MCQs December 19, 2025December 14, 2024 by u930973931_answers 30 min Score: 0 Attempted: 0/30 Subscribe 1. What is a lexical error? (A) An invalid or unrecognized token during scanning (B) An error in program logic (C) A type mismatch in an expression (D) Missing semicolon 2. Which compiler phase primarily detects lexical errors? (A) Syntax analysis (B) Code generation (C) Semantic analysis (D) Lexical analysis 3. Which of the following is an example of a lexical error? (A) Using a variable before declaration (B) Misspelled keyword (C) Missing parenthesis (D) Type mismatch 4. What is a syntax error? (A) An incorrect use of programming language rules or grammar (B) Using an undefined variable (C) Invalid token during scanning (D) Division by zero 5. Which compiler phase detects syntax errors? (A) Syntax analysis (parsing) (B) Lexical analysis (C) Semantic analysis (D) Code generation 6. Which of the following is a common syntax error? (A) Type mismatch (B) Missing semicolon or parenthesis (C) Using uninitialized variable (D) Logical error in expression 7. What is a semantic error? (A) Misspelled keywords (B) Missing braces (C) Invalid tokens (D) Incorrect meaning or usage of statements despite correct syntax 8. Which phase detects semantic errors? (A) Lexical analysis (B) Syntax analysis (C) Code optimization (D) Semantic analysis 9. Which of the following is an example of a semantic error? (A) Using if x = 5 instead of if x == 5 (B) Misspelled variable name (C) Missing semicolon (D) Typing a number incorrectly 10. Which error occurs when a variable is used without being declared? (A) Lexical error (B) Syntax error (C) Runtime error (D) Semantic error 11. What type of error is “unrecognized symbol @”? (A) Runtime error (B) Syntax error (C) Semantic error (D) Lexical error 12. Which error type is caused by violating language grammar rules? (A) Lexical error (B) Semantic error (C) Syntax error (D) Logical error 13. Type mismatches (e.g., assigning a string to an integer variable) are examples of: (A) Semantic errors (B) Syntax errors (C) Lexical errors (D) Runtime errors 14. Which error type is usually detected first during compilation? (A) Syntax errors (B) Runtime errors (C) Semantic errors (D) Lexical errors 15. Missing closing brace } is an example of: (A) Lexical error (B) Runtime error (C) Semantic error (D) Syntax error 16. Using an operator incorrectly on incompatible types is a: (A) Lexical error (B) Semantic error (C) Syntax error (D) Logical error 17. What error occurs when a program contains illegal characters like # in variable names? (A) Semantic error (B) Syntax error (C) Lexical error (D) Runtime error 18. Which error type can cause compilation to fail immediately? (A) Semantic error (B) Syntax error (C) Lexical error (D) Logical error 19. Using a function with wrong number of arguments is a: (A) Lexical error (B) Syntax error (C) Semantic error (D) Runtime error 20. Missing keyword in a statement (e.g., return in a function) is an example of: (A) Lexical error (B) Semantic error (C) Syntax error (D) Runtime error 21. What is the main difference between syntax and semantic errors? (A) Syntax errors occur at runtime; semantic errors at compile-time (B) Syntax errors violate grammar rules; semantic errors violate meaning or logic (C) Syntax errors are optional; semantic errors are mandatory (D) Syntax errors involve variables; semantic errors involve functions 22. Which error type is typically hardest for compilers to detect automatically? (A) Lexical error (B) Semantic error (C) Syntax error (D) Spelling error 23. Division by zero detected at compile-time is an example of: (A) Lexical error (B) Syntax error (C) Semantic error (D) Runtime error 24. Unclosed string literal "Hello is a: (A) Semantic error (B) Syntax error (C) Lexical error (D) Runtime error 25. Which type of error is using while (x > 0) {} without initializing x? (A) Lexical error (B) Semantic error (C) Syntax error (D) Runtime error 26. Misspelled reserved words like pront instead of print is a: (A) Logical error (B) Syntax error (C) Semantic error (D) Lexical error 27. An incorrect if statement structure like if x > 5 print(x) is a: (A) Syntax error (B) Lexical error (C) Semantic error (D) Runtime error 28. Using a variable of type integer in a string concatenation without conversion is a: (A) Lexical error (B) Semantic error (C) Syntax error (D) Runtime error 29. Which error type involves the compiler checking the “meaning” of a statement? (A) Lexical error (B) Syntax error (C) Semantic error (D) Logical error 30. Using a reserved keyword as an identifier is a: (A) Runtime error (B) Syntax error (C) Semantic error (D) Lexical error