Semantic Errors and Type Checking MCQs December 19, 2025December 14, 2024 by u930973931_answers 15 min Score: 0 Attempted: 0/15 Subscribe 1. What is a semantic error? (A) An error in the syntax of a program (B) An error in memory allocation (C) An error in the logic or meaning of a program (D) An error in input/output operations 2. Which of the following is an example of a semantic error? (A) Missing semicolon (B) Using an undeclared variable (C) Forgetting to close a bracket (D) Using incorrect syntax for a loop 3. What is the primary purpose of type checking during semantic analysis? (A) To ensure the program follows the syntax rules (B) To verify that variables are properly declared (C) To ensure the compatibility of operands and operators (D) To generate machine code for the program 4. Which of the following errors is typically caught by type checking? (A) Attempting to assign a string value to an integer variable (B) Incorrect use of parentheses in expressions (C) An undefined variable (D) Incorrect placement of operators 5. Which of the following is NOT a type checking error? (A) Using a string as an integer (B) Declaring a variable without initializing it (C) Calling a function with the wrong number of arguments (D) Assigning a function return type to a variable 6. Which of the following scenarios is likely to result in a semantic error? (A) Forgetting to declare a variable (B) Using a variable before it is assigned a value (C) Using a function with incorrect syntax (D) Forgetting to add a closing parenthesis 7. Which of the following can be considered a type checking issue? (A) Mismatched parentheses in an expression (B) Using a variable without declaring it (C) Forgetting to close a string literal (D) Assigning a float value to an integer variable 8. What happens during type checking in semantic analysis? (A) The types of variables and expressions are verified (B) The syntax of the program is checked (C) The program is converted into machine code (D) The variables are allocated memory 9. Which of the following is a common semantic error involving type checking? (A) Trying to print a string variable (B) Trying to divide an integer by zero (C) Attempting to assign a boolean value to an integer variable (D) Writing a for loop without initializing the counter variable 10. What is the result of attempting to perform a mathematical operation on incompatible types in a strongly-typed language? (A) Compilation continues without issues (B) The compiler issues a semantic error (C) A runtime exception is thrown (D) The compiler automatically converts types 11. What type of error occurs when an expression involves operands of incompatible types? (A) Type error (B) Syntax error (C) Logic error (D) Runtime error 12. Which of the following would likely cause a semantic error due to type mismatch? (A) Adding a number to a string without explicit casting (B) Using a variable before assigning it a value (C) Declaring a variable without a type (D) Writing a function with an incorrect signature 13. What is the result of performing type checking on an assignment like int a = "hello"; in a statically-typed language? (A) The program will run without issues (B) The program will throw a runtime exception (C) A semantic error will be reported (D) The variable a will be automatically converted to a string 14. Which of the following errors is caught during semantic analysis? (A) Incorrect syntax in a loop (B) Incorrect function argument types (C) Missing semicolon at the end of a statement (D) Undefined variables 15. What is the role of a type checker in the semantic analysis phase? (A) To ensure the program follows the rules of the grammar (B) To check for syntax errors in the program (C) To optimize the code for performance (D) To verify that operations are performed on compatible types