CS 200 Principles of Programming Languages Quiz #2 PDF
Document Details
Uploaded by ProfuseDada
Technological Institute of the Philippines
2025
Technological Institute of the Philippines
Tags
Related
Summary
This is a quiz for the CS 200 Principles of Programming Languages course at the Technological Institute of the Philippines for the first semester of 2025. It contains 30 multiple-choice questions on topics like error handling, expressions, type coercion, and short-circuiting.
Full Transcript
TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES QUEZON CITY COMPUTER SCIENCE DEPARTMENT QUIZ #2 - MIDTERM 1st Semester SY2024-2025...
TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES QUEZON CITY COMPUTER SCIENCE DEPARTMENT QUIZ #2 - MIDTERM 1st Semester SY2024-2025 CS 200 – PRINCIPLES OF PROGRAMMING LANGUAGES MULTIPLE CHOICE: Read all the questions carefully. Write the letter of your answer in UPPERCASE format on your answer sheet. (30 points) 1. Which is an example of user-friendly error handling in web applications? A) Displaying error codes directly to users B) Providing helpful, easy-to-understand messages when something goes wrong C) Ignoring errors completely D) None of the above 2. What is an expression in programming? A) A statement that produces a result. B) A combination of values, variables, operators, and functions that produce a result. C) A combination of variables and operators without producing a result. D) None of the above 3. In which of the following expressions is type coercion most likely to occur? A) 3 + 4 B) 3 + "4" C) 3 * 4 D) None of the above 4. What is the role of an assignment statement in programming? A) To create a new variable B) To evaluate an expression and store the result in a variable C) To delete a variable D) None of the above 5. Strict evaluation means: A) Only the necessary parts of an expression are evaluated. B) All parts of the expression are evaluated before execution continues. C) Expressions are never evaluated. D) None of the above 6. Which pattern is useful for operations that may fail temporarily, such as network requests? A) Retry logic B) Error suppression C) Graceful degradation D) All of the above 7. In programming, what is the primary difference between syntax and semantics? A) Syntax defines the meaning; semantics defines the structure. B) Syntax defines the structure; semantics defines the meaning. C) Both syntax and semantics define meaning. D) All of the above 8. In Python, which assignment type allows unpacking values from a sequence into individual variables? A) Chained Assignment B) Simple Assignment C) Unpacking Assignment D) All of the above 9. What is the purpose of providing descriptive error messages? A) To hide error details from the user B) To help developers identify the cause and location of an error C) To reduce program size D) All of the above 10. Which type of error occurs due to incorrect program logic but does not crash the program? A) Syntax error B) Runtime error C) Logical error D) All of the above 11. Lazy evaluation is commonly found in which language type? A) Procedural B) Functional C) Object-oriented D) None of the above 12. In C++, operator overloading allows: A) Using different data types with the same operator. B) Defining new operators. C) Custom definitions for standard operators on user-defined types. D) None of the above 13. In expression typing, what type of language checks types at runtime? A) Statically-typed B) Dynamically-typed C) Weakly-typed D) None of the above 14. Which language does not have increment (++) and decrement (--) operators? A) C++ B) Python C) Java D) None of the above 15. Aliasing occurs when: A) Two variables refer to the same memory location B) A variable is uninitialized C) Two variables have different values D) None of the above 16. What type of assignment allows a value to be assigned to multiple variables at once? A) Compound Assignment B) Chained Assignment C) Simple Assignment D) None of the above 17. Short-circuiting occurs in which types of operations? A) Arithmetic B) Logical C) Bitwise D) None of the above 18. The ternary operator in JavaScript has the form: A) condition ? expr1 : expr2 B) condition && expr1 || expr2 C) expr1 ? condition : expr2 D) None of the above 19. Copy semantics in assignment means: A) The variable points to the memory address of the data. B) The value on the right is copied into the variable on the left. C) The variable on the left is deleted. D) None of the above 20. Which type of error is detected before the program is executed? A) Runtime error B) Syntax error C) Logical error D) None of the above 21. Which language has a safe navigation operator?. A) Python B) C++ C) Kotlin D) None of the above 22. Which of the following scenarios benefits from short-circuiting? A) Executing a function that performs heavy computation B) Checking if a value is null before accessing its properties C) Storing values in a database D) None of the above 23. Which is a best practice for using short-circuit evaluation? A) Using nested short-circuit operators in all expressions B) Keeping conditions clear and avoiding excessive nesting C) Using & for short-circuiting in C++ D) None of the above 24. The try-catch block is used to: A) Perform arithmetic operations. B) Handle runtime errors. C) Define functions. D) None of the above 25. Which example demonstrates the use of short-circuiting to avoid a potential runtime error? A) if (a / b > 2 && a != 0) {...} B) if (a != 0 && b / a > 2) {...} C) if (a == 0 || a / b > 2) {...} D) None of the above 26. Which rule helps determine the order in which operations are performed? A) Associativity B) Precedence C) Typing D) None of the above 27. What is the difference between initialization and assignment? A) Initialization provides an initial value, while assignment updates the variable's value. B) Initialization updates the variable, while assignment only provides an initial value. C) Both are the same. D) None of the above 28. Expression trees are used to: A) Parse expressions. B) Optimize memory usage. C) Visualize the order of evaluation. D) None of the above 29. To handle overflow during type conversion, a programmer can use: A) Error handling mechanisms, like try-catch blocks B) Implicit conversion C) Uninitialized variables D) None of the above 30. A best practice to avoid bugs with type conversions is to: A) Use implicit conversions only B) Use explicit conversions whenever possible C) Avoid conversions altogether D) None of the above