CCS Programming Fundamentals 2 — Questions and Answers
Question 1: Which programming concept allows a function to call itself to solve a problem?
- Iteration
- Recursion (Correct answer)
- Encapsulation
- Polymorphism
Correct answer: Recursion
Recursion is when a function calls itself repeatedly until a base condition is met.
Question 2: In object-oriented programming, what is the term for bundling data and methods that operate on that data within one unit?
- Inheritance
- Polymorphism
- Encapsulation (Correct answer)
- Abstraction
Correct answer: Encapsulation
Encapsulation bundles data and the methods that manipulate that data into a single class or object.
Question 3: What does a 'while' loop check before executing its body?
- The number of iterations completed
- A condition that must be true to continue (Correct answer)
- The return value of the loop body
- The size of an array
Correct answer: A condition that must be true to continue
A while loop evaluates its condition before each iteration and exits when the condition becomes false.
Question 4: Which data structure follows the Last-In, First-Out (LIFO) principle?
- Queue
- Stack (Correct answer)
- Linked list
- Tree
Correct answer: Stack
A stack operates on LIFO, meaning the last element added is the first one removed.
Question 5: What is the result of the expression 7 % 3 in most programming languages?
- 2
- 1 (Correct answer)
- 3
- 0
Correct answer: 1
The modulo operator (%) returns the remainder of division; 7 divided by 3 is 2 with remainder 1.
Question 6: Which type of error occurs when code is syntactically correct but produces an unintended result?
- Syntax error
- Runtime error
- Logic error (Correct answer)
- Compilation error
Correct answer: Logic error
A logic error means the program runs without crashing but produces incorrect output due to flawed reasoning.
Question 7: What does the term 'scope' refer to in programming?
- The size of a variable in memory
- The visibility and lifetime of a variable (Correct answer)
- The number of parameters a function accepts
- The speed of code execution
Correct answer: The visibility and lifetime of a variable
Scope defines where in the code a variable can be accessed and how long it exists.
Which programming concept allows a function to call itself to solve a problem?