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
What type of assignment allows a value to be assigned to multiple variables at once?
A) Compound Assignment
C) Simple Assignment
B) Chained Assignment
D) None of the above
Chained Assignment
Short-circuiting occurs in which types of operations?
A) Arithmetic C) Bitwise
B) Logical D) None of the above
Logical
The ternary operator in JavaScript has the form:
A) condition ? expr1 : expr2
C) expr1 ? condition : expr2
B) condition && expr1 || expr2
D) None of the above
condition ? expr1 : expr2
Copy semantics in assignment means:
A) The variable points to the memory address of the data.
C) The variable on the left is deleted.
B) The value on the right is copied into the variable on the left.
D) None of the above
The value on the right is copied into the variable on the left.
. 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
C) Uninitialized variables
Error handling mechanisms, like try-catch blocks
A best practice to avoid bugs with type conversions is to:
A) Use implicit conversions only
C) Avoid conversions altogether
B) Use explicit conversions whenever possible D) None of the above
Use explicit conversions whenever possible
Lazy evaluation is commonly found in which language type?
A) Procedural C) Object-oriented
B) Functional D) None of the above
Functional
. In C++, operator overloading allows:
A) Using different data types with the same operator.
C) Custom definitions for standard operators on user-defined types.
B) Defining new operators.
D) None of the above
Custom definitions for standard operators on user-defined types.
. In expression typing, what type of language checks types at runtime?
A) Statically-typed C) Weakly-typed
B) Dynamically-typed D) None of the above
Dynamically-typed
. Lazy evaluation is useful because it:
A) Reduces memory usage.
C) Avoids computation until needed.
B) Ensures all expressions are evaluated.
D) None of the above
None of the above
Which language does not support operator overloading?
A) Python C) C++
B) Java D) None of the above
Java
Which statement best describes parallel assignment?
A) It allows assigning the same value to multiple variables.
B) It allows assigning different values to multiple variables in one line.
C) It combines an operation with assignment
D) D) None of the above
It allows assigning different values to multiple variables in one line.
In C, which syntax is used to cast a variable to an integer?
A) int(x)
C) int x
B) (int) x
D) None of the above
(int) x
Type demotion may lead to:
A) Increased precision
C) More memory allocation
B) Loss of precision
D) None of the above
Loss of precision
Order of operations, also known as precedence rules, is used to resolve expression ambiguity T/F
T
. Operator overloading allows operators to have unique functionality with user-defined types in some languages.T/F
T
. In C++, both prefix and postfix forms of the increment operator ++ yield the same result.T/F
F
Short-circuit evaluation can improve performance by stopping further evaluation once the result is determined.T/F
T
The syntax for assignment is identical in all programming languages.T/F
F
Reference semantics are commonly used with primitive types in programming.T/F
T
Custom conversion functions allow programmers to define how objects are converted between types.T/F
T
Rounding errors are typically not a concern in floating-point arithmetic conversions.T/F
F
. In C++, operator overloading cannot be used to define custom type conversions.T/F
F
Type conversion is the process of changing a variable from one type to another, often necessary for mixed-type
operations.T/F
T