CCS Programming Fundamentals 3 — Questions and Answers
Question 1: Which of the following best describes an algorithm?
- A programming language feature
- A step-by-step procedure for solving a problem (Correct answer)
- A type of variable
- A database query
Correct answer: A step-by-step procedure for solving a problem
An algorithm is a finite, ordered set of instructions designed to solve a specific problem or perform a task.
Question 2: What is the primary purpose of a function parameter?
- To store the function's return value
- To pass data into a function when it is called (Correct answer)
- To declare a global variable
- To define the function's output type
Correct answer: To pass data into a function when it is called
Parameters allow callers to supply input values that the function uses during its execution.
Question 3: In most programming languages, arrays use which type of indexing by default?
- 1-based indexing
- 0-based indexing (Correct answer)
- 2-based indexing
- Random indexing
Correct answer: 0-based indexing
Most languages like C, Java, and Python start array indices at 0, so the first element is at index 0.
Question 4: What is a 'boolean' data type used for?
- Storing large numbers
- Representing true or false values (Correct answer)
- Holding character strings
- Performing arithmetic operations
Correct answer: Representing true or false values
A boolean data type holds only two possible values: true or false, commonly used in conditional logic.
Question 5: Which control structure is best suited when you need to execute a block of code for each item in a collection?
- if-else statement
- switch statement
- for loop (Correct answer)
- do-while loop
Correct answer: for loop
A for loop is designed to iterate over a sequence or collection, executing the body for each element.
Question 6: What does it mean when a variable is declared as a 'constant'?
- Its value can be changed at any time
- Its value cannot be changed after it is set (Correct answer)
- It is always a global variable
- It is automatically initialized to zero
Correct answer: Its value cannot be changed after it is set
A constant is a named value that is assigned once and cannot be modified during program execution.
Question 7: Which sorting algorithm repeatedly swaps adjacent elements that are in the wrong order?
- Merge sort
- Quick sort
- Bubble sort (Correct answer)
- Insertion sort
Correct answer: Bubble sort
Bubble sort works by comparing and swapping adjacent elements repeatedly until the list is sorted.
Which of the following best describes an algorithm?