PPL Midterm Flashcards

1
Q

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

A

if (a != 0 && b / a > 2) {…}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which rule helps determine the order in which operations are performed?
A) Associativity C) Typing
B) Precedence D) None of the above

A

Precedence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

Initialization provides an initial value, while assignment updates the variable’s value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Expression trees are used to:
A) Parse expressions.
C) Visualize the order of evaluation.
B) Optimize memory usage.
D) None of the above

A

Visualize the order of evaluation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

Error handling mechanisms, like try-catch blocks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

Use explicit conversions whenever possible

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

Providing helpful, easy-to-understand messages when something goes wrong

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A combination of values, variables, operators, and functions that produce a result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

. 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

A

3 + “4”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

. 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

A

To evaluate an expression and store the result in a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

All parts of the expression are evaluated before execution continues.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

Retry logic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

. 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

A

Syntax defines the structure; semantics defines the meaning.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

. 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

A

Unpacking Assignment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

Logical error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

A

Two variables refer to the same memory location

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

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

A

Chained Assignment

18
Q

Short-circuiting occurs in which types of operations?
A) Arithmetic C) Bitwise
B) Logical D) None of the above

A

Logical

19
Q

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

A

condition ? expr1 : expr2

20
Q

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

A

The value on the right is copied into the variable on the left.

21
Q

. 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

A

Error handling mechanisms, like try-catch blocks

22
Q

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

A

Use explicit conversions whenever possible

23
Q

Lazy evaluation is commonly found in which language type?
A) Procedural C) Object-oriented
B) Functional D) None of the above

A

Functional

24
Q

. 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

A

Custom definitions for standard operators on user-defined types.

25
Q

. 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

A

Dynamically-typed

26
Q

. 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

A

None of the above

27
Q

Which language does not support operator overloading?
A) Python C) C++
B) Java D) None of the above

A

Java

28
Q

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

A

It allows assigning different values to multiple variables in one line.

29
Q

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

A

(int) x

30
Q

Type demotion may lead to:
A) Increased precision
C) More memory allocation
B) Loss of precision
D) None of the above

A

Loss of precision

31
Q

Order of operations, also known as precedence rules, is used to resolve expression ambiguity T/F

A

T

32
Q

. Operator overloading allows operators to have unique functionality with user-defined types in some languages.T/F

A

T

33
Q

. In C++, both prefix and postfix forms of the increment operator ++ yield the same result.T/F

A

F

34
Q

Short-circuit evaluation can improve performance by stopping further evaluation once the result is determined.T/F

A

T

35
Q

The syntax for assignment is identical in all programming languages.T/F

A

F

36
Q

Reference semantics are commonly used with primitive types in programming.T/F

A

T

37
Q

Custom conversion functions allow programmers to define how objects are converted between types.T/F

A

T

38
Q

Rounding errors are typically not a concern in floating-point arithmetic conversions.T/F

A

F

39
Q

. In C++, operator overloading cannot be used to define custom type conversions.T/F

A

F

40
Q

Type conversion is the process of changing a variable from one type to another, often necessary for mixed-type
operations.T/F

A

T