PPL Midterm Flashcards
Which example demonstrates the use of short-circuiting to avoid a potential runtime error?
A) if (a / b > 2 && a != 0) {…}
C) if (a == 0 || a / b > 2) {…}
B) if (a != 0 && b / a > 2) {…}
D) None of the above
if (a != 0 && b / a > 2) {…}
Which rule helps determine the order in which operations are performed?
A) Associativity C) Typing
B) Precedence D) None of the above
Precedence
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
Initialization provides an initial value, while assignment updates the variable’s value.
Expression trees are used to:
A) Parse expressions.
C) Visualize the order of evaluation.
B) Optimize memory usage.
D) None of the above
Visualize the order of evaluation.
To handle overflow during type conversion, a programmer can use:
A) Error handling mechanisms, like try-catch blocks
C) Uninitialized variables
B) Implicit conversion
D) None of the above
Error handling mechanisms, like try-catch blocks
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
Use explicit conversions whenever possible
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
Providing helpful, easy-to-understand messages when something goes wrong
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
A combination of values, variables, operators, and functions that produce a result.
. In which of the following expressions is type coercion most likely to occur?
A) 3 + 4
C) 3 * 4
B) 3 + “4”
D) None of the above
3 + “4”
. What is the role of an assignment statement in programming?
A) To create a new variable
C) To delete a variable
B) To evaluate an expression and store the result in a variable
D) None of the above
To evaluate an expression and store the result in a variable
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
All parts of the expression are evaluated before execution continues.
Which pattern is useful for operations that may fail temporarily, such as network requests?
A) Retry logic C) Graceful degradation
B) Error suppression D) None of the above
Retry logic
. 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
Syntax defines the structure; semantics defines the meaning.
. In Python, which assignment type allows unpacking values from a sequence into individual variables?
A) Chained Assignment
C) Unpacking Assignment
B) Simple Assignment
D) None of the above
Unpacking Assignment
Which type of error occurs due to incorrect program logic but does not crash the program?
A) Syntax error C) Logical error
B) Runtime error D) None of the above
Logical error
Aliasing occurs when:
A) Two variables refer to the same memory location
C) Two variables have different values
B) A variable is uninitialized
D) None of the above
Two variables refer to the same memory location