CPA Programming Fundamentals & Logic 2 — Questions and Answers
Question 1: What is the output of the following pseudocode? x = 10; y = 3; print(x MOD y)
- 3
- 1 (Correct answer)
- 0
- 7
Correct answer: 1
The MOD (modulo) operator returns the remainder of 10 divided by 3, which is 1.
Question 2: Which data structure follows the Last-In, First-Out (LIFO) principle?
- Queue
- Stack (Correct answer)
- Linked List
- Tree
Correct answer: Stack
A stack follows LIFO, meaning the last element pushed is the first one popped.
Question 3: A variable declared inside a function that cannot be accessed outside it has what kind of scope?
- Global scope
- Module scope
- Local scope (Correct answer)
- Class scope
Correct answer: Local scope
Variables declared inside a function have local scope and are inaccessible outside that function.
Question 4: What logical operator returns TRUE only when both operands are TRUE?
- OR
- NOT
- XOR
- AND (Correct answer)
Correct answer: AND
The AND operator evaluates to TRUE only if both the left and right operands are TRUE.
Question 5: In a for-loop defined as 'for i = 1 to 5', how many times does the loop body execute?
- 4
- 5 (Correct answer)
- 6
- 0
Correct answer: 5
The loop iterates for i = 1, 2, 3, 4, 5, so the body executes exactly 5 times.
Question 6: Which of the following best describes a constant in programming?
- A value that changes during execution
- A named memory location whose value cannot be changed after assignment (Correct answer)
- A function that always returns the same output
- A variable with global scope
Correct answer: A named memory location whose value cannot be changed after assignment
A constant is a named storage location whose value is fixed and cannot be modified after it is initially set.
Question 7: What is the result of evaluating: TRUE OR FALSE AND FALSE?
- FALSE
- TRUE (Correct answer)
- Undefined
- Error
Correct answer: TRUE
AND has higher precedence than OR, so FALSE AND FALSE = FALSE first, then TRUE OR FALSE = TRUE.
What is the output of the following pseudocode? x = 10; y = 3; print(x MOD y)