50 multiple-choice questions with answers and detailed explanations. Untimed — choose an answer to check it instantly.
0/50 answered0 correct
Question 1 of 50
What is a function in programming?
Correct answer: C) A reusable named block of code that performs a task
Explanation: A function groups statements under a name so the logic can be invoked repeatedly from different places, promoting reuse and reducing duplication.
Question 2 of 50
What is a function parameter?
Correct answer: D) A named input the function receives when called
Explanation: A parameter is a named variable in the function definition that receives a value, called an argument, when the function is invoked.
Question 3 of 50
What is a return value?
Correct answer: A) The result a function sends back to its caller
Explanation: A return value is the result a function passes back to the code that called it, allowing the caller to use the computed outcome.
Question 4 of 50
What happens when a function has no explicit return statement?
Correct answer: B) It typically returns a default value such as null or none
Explanation: A function without an explicit return usually returns a default empty value such as null, none, or undefined, depending on the language.
Question 5 of 50
What is the main benefit of decomposing a program into functions?
Correct answer: C) Improved readability, reuse, and easier testing
Explanation: Breaking a program into functions makes each piece easier to understand, reuse, and test independently, and localizes changes when requirements evolve.
Question 6 of 50
What is recursion?
Correct answer: D) A function calling itself to solve smaller instances of a problem
Explanation: Recursion solves a problem by having a function call itself on progressively smaller inputs until reaching a base case that returns directly.
Question 7 of 50
What is essential to prevent infinite recursion?
Correct answer: A) A base case that stops further recursive calls
Explanation: A base case defines the condition under which the function returns without recursing further. Without it, recursion continues until the call stack overflows.
Question 8 of 50
What is an array?
Correct answer: B) An ordered collection of elements accessed by index
Explanation: An array stores multiple values of typically the same type in an ordered structure, with each element accessible by its numeric index position.
Question 9 of 50
How do you access the third element of an array named data using zero-based indexing?
Correct answer: C) data[2]
Explanation: With zero-based indexing the first element is at index 0, so the third element is at index 2.
Question 10 of 50
What is an array index out of bounds error?
Correct answer: D) Accessing a position outside the array's valid range
Explanation: An out of bounds error occurs when code accesses an index below zero or at or beyond the array length, typically causing a runtime exception.
Question 11 of 50
What is a two-dimensional array commonly used to represent?
Correct answer: A) A grid or table of rows and columns
Explanation: A two-dimensional array stores data in rows and columns, naturally representing grids, matrices, tables, or game boards.
Question 12 of 50
How do you typically iterate through every element of an array?
Correct answer: B) Using a loop from the first index to the last
Explanation: A loop that runs from index 0 through length minus one visits each element in turn, allowing uniform processing of the whole collection.
Question 13 of 50
What is a list or dynamic array?
Correct answer: C) A collection that can grow or shrink during execution
Explanation: A dynamic array or list can change size at runtime as elements are added or removed, unlike a fixed-size array declared with a set capacity.
Question 14 of 50
What is the length property of a string?
Correct answer: D) The number of characters it contains
Explanation: The length of a string is the count of characters it contains, commonly used for validation and for controlling iteration over the string.
Question 15 of 50
What does a substring operation do?
Correct answer: A) Extracts a portion of a string
Explanation: A substring operation returns a specified portion of a string, typically defined by a starting position and a length or ending position.
Question 16 of 50
Why should strings be compared with a comparison function rather than reference equality in some languages?
Correct answer: B) Reference comparison may test identity rather than content
Explanation: In some languages the equality operator compares object references rather than character content, so two separate strings with identical text could compare as unequal.
Question 17 of 50
What is string immutability?
Correct answer: C) A string's contents cannot be changed after creation
Explanation: In languages with immutable strings, operations that appear to modify a string actually create a new string, leaving the original unchanged.
Question 18 of 50
What is a linear search?
Correct answer: D) Checking each element in sequence until the target is found
Explanation: A linear search examines elements one at a time from the beginning until it finds the target or exhausts the collection, working on unsorted data.
Question 19 of 50
What is a prerequisite for using binary search?
Correct answer: A) The collection must already be sorted
Explanation: Binary search repeatedly halves the search range by comparing against the middle element, which only works correctly if the data is sorted.
Question 20 of 50
Why is binary search more efficient than linear search on large sorted data?
Correct answer: B) It eliminates half the remaining elements with each comparison
Explanation: Binary search discards half the remaining candidates each step, giving logarithmic time complexity compared with the linear time of sequential search.
Question 21 of 50
What does a sorting algorithm do?
Correct answer: C) Arranges elements into a specified order
Explanation: A sorting algorithm rearranges a collection into ascending or descending order according to a comparison rule, enabling efficient searching and presentation.
Question 22 of 50
What is the basic idea of bubble sort?
Correct answer: D) Repeatedly comparing adjacent elements and swapping those out of order
Explanation: Bubble sort repeatedly steps through the list comparing adjacent pairs and swapping them when out of order, so larger values gradually move toward the end.
Question 23 of 50
What does 'time complexity' describe?
Correct answer: A) How an algorithm's running time grows with input size
Explanation: Time complexity describes how running time scales as input size grows, expressed in Big O notation independently of specific hardware.
Question 24 of 50
What does O(n) time complexity mean?
Correct answer: B) Running time grows proportionally with the input size
Explanation: O(n) or linear time means the work grows in direct proportion to the number of input elements, as in a single pass through an array.
Question 25 of 50
What does O(1) time complexity indicate?
Correct answer: C) Constant time regardless of input size
Explanation: O(1) or constant time means the operation takes the same amount of time regardless of how large the input is, such as accessing an array element by index.
Question 26 of 50
What is a dictionary or hash map?
Correct answer: D) A collection storing key-value pairs for fast lookup by key
Explanation: A dictionary stores key-value pairs and uses hashing to retrieve values by key in near-constant time, unlike scanning a list sequentially.
Question 27 of 50
What is exception handling?
Correct answer: A) Managing runtime errors gracefully rather than crashing
Explanation: Exception handling catches runtime errors so the program can respond appropriately, such as logging the issue or prompting the user, instead of terminating abruptly.
Question 28 of 50
What is the purpose of a try-catch block?
Correct answer: B) Attempting risky code and handling any resulting exception
Explanation: The try block contains code that might throw an exception, and the catch block specifies how to respond if one occurs, keeping the program running.
Question 29 of 50
What is the purpose of a finally block?
Correct answer: C) Running cleanup code whether or not an exception occurred
Explanation: A finally block executes regardless of whether an exception was thrown, making it suitable for cleanup such as closing files or releasing resources.
Question 30 of 50
What is a common cause of a divide-by-zero error?
Correct answer: D) Failing to validate a divisor before performing division
Explanation: Dividing by a variable that holds zero raises an error at runtime. Validating the divisor before dividing prevents this common defect.
Question 31 of 50
What is file input and output (I/O)?
Correct answer: A) Reading data from and writing data to files
Explanation: File I/O allows programs to read data from files and write results back, providing persistence beyond the lifetime of a single program run.
Question 32 of 50
Why should files be closed after use?
Correct answer: B) To release system resources and ensure data is written
Explanation: Closing a file releases the operating system handle and flushes buffered data to disk, preventing resource leaks and data loss.
Question 33 of 50
What is a code library or module?
Correct answer: C) Reusable code packaged for use across programs
Explanation: A library or module packages reusable functions and definitions that programs can import, avoiding reimplementation of common functionality.
Question 34 of 50
What is the benefit of using existing libraries?
Correct answer: D) Saving development time and using well-tested code
Explanation: Established libraries provide tested, maintained implementations of common tasks, saving development effort and typically producing more reliable results than reinventing them.
Question 35 of 50
What is version control used for?
Correct answer: A) Tracking changes to code over time and coordinating collaboration
Explanation: Version control records the history of changes, allowing developers to review history, revert mistakes, work in parallel branches, and merge contributions.
Question 36 of 50
What is a commit in version control?
Correct answer: B) A recorded snapshot of changes with a descriptive message
Explanation: A commit records a set of changes to the repository along with a message explaining what changed and why, forming a point in the project history.
Question 37 of 50
What is the purpose of code testing?
Correct answer: C) Verifying that code behaves correctly under expected and edge conditions
Explanation: Testing verifies that code produces correct results for expected inputs, boundary values, and error conditions, catching defects before they reach users.
Question 38 of 50
What is a unit test?
Correct answer: D) A test verifying a single small component in isolation
Explanation: A unit test verifies one small unit of code, typically a single function, in isolation from dependencies, providing fast and precise feedback on defects.
Question 39 of 50
What is a test case for a boundary condition?
Correct answer: A) A test using values at the edges of the valid range
Explanation: Boundary testing uses values at the limits of valid ranges, such as minimum, maximum, and just outside, because defects cluster at these edges.
Question 40 of 50
What is refactoring?
Correct answer: B) Restructuring existing code without changing its external behavior
Explanation: Refactoring improves the internal structure and readability of code while preserving its observable behavior, making future changes easier and safer.
Question 41 of 50
Why is code readability important?
Correct answer: C) Code is read far more often than it is written and must be maintained
Explanation: Developers spend far more time reading and modifying code than writing it initially, so clear structure and naming substantially reduce maintenance cost and defects.
Question 42 of 50
What is the DRY principle in programming?
Correct answer: D) Do not Repeat Yourself: avoid duplicating logic
Explanation: The DRY principle advises against duplicating logic, because repeated code must be changed in multiple places and easily becomes inconsistent.
Question 43 of 50
What is the purpose of indentation in code?
Correct answer: A) Showing structure and nesting to make logic clear
Explanation: Indentation visually conveys block structure and nesting. In some languages, such as Python, it is syntactically required to define code blocks.
Question 44 of 50
What is a code review?
Correct answer: B) Systematic examination of code by other developers
Explanation: Code review has peers examine changes to catch defects, improve design, share knowledge, and maintain consistent standards before code is merged.
Question 45 of 50
What is an integrated development environment (IDE)?
Correct answer: C) Software combining an editor, debugger, and build tools
Explanation: An IDE integrates an editor, compiler or interpreter, debugger, and other tools into one application, streamlining the development workflow.
Question 46 of 50
What is the primary purpose of program documentation?
Correct answer: D) Explaining how the software works and how to use or maintain it
Explanation: Documentation explains purpose, usage, and design decisions so that users can operate the software and future developers can maintain it effectively.
Question 47 of 50
What is modular programming?
Correct answer: A) Organizing a program into independent, interchangeable components
Explanation: Modular programming divides a system into self-contained modules with clear interfaces, making the program easier to develop, test, understand, and modify.
Question 48 of 50
What is the software development life cycle (SDLC)?
Correct answer: B) The structured phases from requirements through maintenance
Explanation: The SDLC describes the phases of software development, typically requirements, design, implementation, testing, deployment, and maintenance.
Question 49 of 50
Why are requirements gathered before coding begins?
Correct answer: C) To ensure the software solves the actual problem stakeholders have
Explanation: Clear requirements establish what the software must do, preventing wasted effort building the wrong solution and providing the basis for testing.
Question 50 of 50
What is the value of writing a program in small, testable increments?
Correct answer: D) Defects are found early when they are cheap and easy to fix
Explanation: Building and testing incrementally surfaces defects close to when they are introduced, when the context is fresh and the fix is far less costly than after full integration.
Set 5 complete
You scored 0%
0 correct out of 0 answered (50 questions in this set).