Programming fundamentals quiz
Test variables, constants, data types, conditions, loops, arrays, functions, and common programming errors.
syllabus — topic scope & references
- Choose suitable data types and control structures
- Trace arrays and accumulators
- Distinguish syntax errors from logic errors
Cambridge IGCSE 0478 (2026–2028): 8.1, 8.2 Programming concepts; arrays.
IB Computer Science (first assessment 2027): B.2 Programming.
Original practice on shared foundations. Topic-area links do not imply complete syllabus or SL/HL coverage. Not affiliated with or endorsed by Cambridge or the IB.
Related: Algorithms and computational thinking · Boolean logic and truth tables · Databases and SQL
review — read all questions & worked answers
Programming fundamentals: questions, answers & explanations
This is the readable reference for the same 10 MCQs. Close this file to continue your quiz, or type quiz to start again.
1. Which data type is most suitable for the number of students in a class?
- a) Integer
- b) Boolean
- c) Character
Answer: a) Integer
A count of students is a whole number, so an integer is suitable. A Boolean has two logical values; a character holds one character.
2. How does a constant differ from a variable?
- a) A constant must contain text
- b) A constant is intended to retain its assigned value during execution
- c) A variable can hold only one digit
Answer: b) A constant is intended to retain its assigned value during execution
A constant represents a value that should not be reassigned. A variable can be updated as a program runs.
3. Which control structure chooses between paths based on a condition?
- a) A comment
- b) An assignment alone
- c) Selection, such as IF...ELSE
Answer: c) Selection, such as IF...ELSE
Selection runs a particular path depending on a Boolean condition. IF...ELSE is one way to express it.
4. How many times can a pre-condition WHILE loop run if its condition is false at the first check?
- a) Zero
- b) Exactly once
- c) At least twice
Answer: a) Zero
A pre-condition loop tests before entering its body. If the condition starts false, the body is skipped.
5. Trace this pseudocode: count ← 0 FOR EACH value IN [4, 8, 2] count ← count + 1 ENDFOR What is count?
- a) 14
- b) 3
- c) 1
Answer: b) 3
The loop increments once for each of three items. It counts items rather than adding their values.
6. Trace this pseudocode: total ← 0 FOR EACH value IN [4, 8, 2] total ← total + value ENDFOR What is total?
- a) 3
- b) 8
- c) 14
Answer: c) 14
This accumulator adds the values: 4 + 8 + 2 = 14. It totals values rather than counting items.
7. The array [4, 7, 9] uses zero-based indexing. What is the value at index 1?
- a) 7
- b) 4
- c) 9
Answer: a) 7
With zero-based indexing, index 0 holds 4, index 1 holds 7, and index 2 holds 9.
8. In this pseudocode, FUNCTION double(n) RETURNS n * 2. What is double(6)?
- a) 3
- b) 12
- c) 36
Answer: b) 12
The function multiplies its input by 2 and returns that result. With n = 6, the return value is 12.
9. Which example is a logic error?
- a) A missing closing parenthesis that breaks the language's syntax
- b) An unclosed quotation mark in source code
- c) A program runs but calculates a rectangle's area using width + height
Answer: c) A program runs but calculates a rectangle's area using width + height
The program follows the language's syntax but uses the wrong method. A rectangle's area should be width × height.
10. A condition must represent either true or false. Which data type matches that purpose?
- a) Boolean
- b) Real
- c) String
Answer: a) Boolean
A Boolean represents a logical true or false value and is used in conditions.
↑ ↓ recall commands · Tab autocomplete · Enter run
