C++ Certified Professional Programmer (CPP) — Questions and Answers
Question 1: What is the primary use case of a hash table?
- Storing data in sorted order
- Direct access to data using a key (Correct answer)
- Linking data elements together
- Recursively sorting data
Correct answer: Direct access to data using a key
A hash table's fundamental strength lies in its ability to map keys to values, allowing for nearly instantaneous retrieval of data. By using a hash function, it computes an index directly from a given key, enabling O(1) average-case time complexity for operations like insertion, deletion, and lookup. This direct access capability makes it ideal for applications requiring fast data retrieval based on unique identifiers.
Question 2: What is the fail-fast principle in error handling?
- Restarting the service after any failure
- Crashing the application immediately on any error
- Detecting and reporting errors as early as possible rather than propagating invalid state deeper into the system (Correct answer)
- Skipping failed operations and continuing execution
Correct answer: Detecting and reporting errors as early as possible rather than propagating invalid state deeper into the system
Fail-fast surfaces bugs immediately at their source before corrupted state propagates, making root cause analysis far easier.
Question 3: What is the difference between method overloading and method overriding?
- Overloading changes return type; overriding changes parameter types
- Overloading is compile-time; overriding is always static
- Overloading defines multiple methods with the same name but different signatures; overriding redefines a superclass method in a subclass (Correct answer)
- Overloading only works with constructors; overriding works with all methods
Correct answer: Overloading defines multiple methods with the same name but different signatures; overriding redefines a superclass method in a subclass
Overloading uses the same method name with different parameter lists in the same class, while overriding redefines an inherited method in a subclass.
Question 4: What does O(log n) time complexity represent?
- Exponential growth
- Quadratic growth
- Logarithmic growth (Correct answer)
- Linear growth
Correct answer: Logarithmic growth
O(log n) time complexity signifies logarithmic growth, meaning the execution time or space requirements of an algorithm increase very slowly as the input size (n) grows. For example, doubling the input size only adds a constant amount of work, not doubles it. This efficiency is characteristic of algorithms that repeatedly divide the problem into smaller subproblems, such as binary search or operations on balanced binary trees.
Question 5: Which of the following is a feature of the Python programming language?
- Dynamic typing (Correct answer)
- Low-level language
- Used only for web development
- Compulsory type declaration
Correct answer: Dynamic typing
Python is a dynamically typed language, meaning that variable types are inferred at runtime, and explicit type declarations are not required. This allows for greater flexibility and faster development compared to statically typed languages. It is also a high-level language, not low-level, and its use extends far beyond just web development.
Question 6: What is the Java Memory Model (JMM) relevant to CPP-level knowledge?
- It defines how Java allocates heap vs stack memory
- It specifies rules about when writes by one thread become visible to other threads (Correct answer)
- It controls garbage collection frequency
- It dictates the maximum number of threads allowed
Correct answer: It specifies rules about when writes by one thread become visible to other threads
The JMM defines visibility and ordering guarantees for shared variables across threads, underpinning the behavior of volatile, synchronized, and atomic constructs.
Question 7: What is the Factory Method design pattern?
- A pattern caching and reusing objects
- A static method that initializes all application objects at startup
- A pattern defining an interface for creating an object but letting subclasses decide which class to instantiate (Correct answer)
- A pattern for building complex objects step by step
Correct answer: A pattern defining an interface for creating an object but letting subclasses decide which class to instantiate
The Factory Method pattern delegates object creation to subclasses, allowing a class to defer instantiation of the exact type it will use.
Question 8: What does 'Big O notation' measure in algorithm performance?
- Memory address size
- How an algorithm's runtime or space requirements grow relative to input size (Correct answer)
- Exact execution time in milliseconds
- The number of CPU cores used
Correct answer: How an algorithm's runtime or space requirements grow relative to input size
Big O notation describes the upper bound of an algorithm's time or space complexity as a function of input size.
Question 9: Which SQL clause is used to filter results after an aggregate function has been applied?
- WHERE
- GROUP BY
- HAVING (Correct answer)
- ORDER BY
Correct answer: HAVING
HAVING filters rows after GROUP BY aggregation, whereas WHERE filters rows before aggregation occurs.
Question 10: What is a semaphore in concurrent programming?
- A hardware interrupt handler
- A way to terminate threads gracefully
- A signaling mechanism that controls access to a limited number of resources using a counter (Correct answer)
- A type of thread pool
Correct answer: A signaling mechanism that controls access to a limited number of resources using a counter
A semaphore maintains a count representing available resource slots; threads wait when the count is zero and signal to increment it when done.
Question 11: What is the primary purpose of an algorithm?
- To store data efficiently
- To control hardware components
- To increase the complexity of a task
- To solve problems using a defined sequence of steps (Correct answer)
Correct answer: To solve problems using a defined sequence of steps
The primary purpose of an algorithm is to solve problems by providing a defined, finite sequence of unambiguous steps or instructions. It acts as a blueprint for computation, taking an input, performing a series of operations, and producing a desired output. Algorithms are fundamental to all computer programming.
Question 12: What is a constructor in OOP?
- A special method called automatically when an object is created (Correct answer)
- A method that destroys an object
- A static factory method
- A method that copies an object
Correct answer: A special method called automatically when an object is created
A constructor is a special method invoked automatically upon object creation to initialize its state.
Question 13: Which design concept is described as 'favoring composition over inheritance'?
- Building complex behavior by combining simpler objects rather than extending class hierarchies (Correct answer)
- Using only static methods
- Inheriting from multiple base classes
- Using abstract classes exclusively
Correct answer: Building complex behavior by combining simpler objects rather than extending class hierarchies
Favoring composition means assembling objects with desired behaviors rather than relying on deep inheritance chains, improving flexibility.
Question 14: A database VIEW is best described as:
- A physical copy of a table stored on disk for fast access
- A type of index that spans multiple tables
- A database trigger that fires on SELECT statements
- A named, saved SQL query that behaves like a virtual table (Correct answer)
Correct answer: A named, saved SQL query that behaves like a virtual table
A view is a stored query that presents data from one or more underlying tables as if it were a table itself, without storing the data redundantly.
Question 15: Which SQL JOIN returns all rows from the left table and matching rows from the right table, with NULLs for non-matching right rows?
- FULL OUTER JOIN
- LEFT OUTER JOIN (Correct answer)
- INNER JOIN
- RIGHT OUTER JOIN
Correct answer: LEFT OUTER JOIN
A LEFT OUTER JOIN returns all rows from the left table plus matched rows from the right; unmatched right-side columns are filled with NULL.
Question 16: What is the role of the 'this' keyword in OOP languages?
- Refers to the parent class
- Refers to the current object instance (Correct answer)
- Creates a new object
- Refers to a static context
Correct answer: Refers to the current object instance
'this' is a reference to the current object instance, used to differentiate instance variables from local variables.
Question 17: In which phase of SDLC is the system built and coded?
- Planning
- Development (Correct answer)
- Design
- Testing
Correct answer: Development
The Development phase (also known as Implementation or Coding) is where the actual software system is built and coded according to the design specifications. Programmers write the code, integrate different modules, and perform unit testing to ensure individual components function correctly. This phase translates the design into a working product.
Question 18: What is a security audit in the context of software development?
- Automatically scanning code for style violations
- Measuring application performance under load
- Running penetration tests against a production system
- A systematic review of code and architecture to identify security vulnerabilities and compliance gaps (Correct answer)
Correct answer: A systematic review of code and architecture to identify security vulnerabilities and compliance gaps
A security audit examines code, configurations, and architecture to find vulnerabilities before attackers do, often including manual review and automated scanning.
Question 19: Which of the following is a framework used for building mobile applications?
- Spring Boot
- Flutter (Correct answer)
- Ruby on Rails
- Django
Correct answer: Flutter
Flutter is an open-source UI software development kit created by Google, specifically designed for building natively compiled applications for mobile, web, and desktop from a single codebase. It provides a complete framework for developing cross-platform mobile applications. Django, Ruby on Rails, and Spring Boot are frameworks primarily used for web backend development.
Question 20: What is a binary search algorithm?
- It is a technique for sorting a binary tree
- It is a method to find an element in an unsorted array
- It is a method to sort elements in an array
- It divides the list into two and searches through one half (Correct answer)
Correct answer: It divides the list into two and searches through one half
A binary search algorithm is an efficient method for finding an element within a sorted list or array. It works by repeatedly dividing the search interval in half. If the middle element is not the target, the algorithm determines whether to continue searching in the left or right half, effectively eliminating half of the remaining elements in each step.
Question 21: What is object pooling as a performance optimization technique?
- Pooling CPU threads into a fixed-size group
- Reusing a set of pre-allocated objects instead of repeatedly creating and destroying them (Correct answer)
- Sharing database connection strings
- Combining small objects into one large object
Correct answer: Reusing a set of pre-allocated objects instead of repeatedly creating and destroying them
Object pooling reduces garbage collection pressure and allocation overhead by recycling expensive-to-create objects.
Question 22: What happens during the Maintenance phase of SDLC?
- Continuous testing of the system
- Creating system requirements
- System design adjustments
- Fixing bugs and making updates (Correct answer)
Correct answer: Fixing bugs and making updates
During the Maintenance phase of SDLC, the software system is continuously monitored and supported after its deployment. This involves fixing newly discovered bugs, implementing enhancements, adapting the system to new environments or technologies, and making updates to ensure its ongoing functionality and relevance over time.
Question 23: What is the difference between parallelism and concurrency?
- They are identical concepts
- Concurrency is about dealing with multiple tasks at once (possibly interleaved); parallelism is executing multiple tasks simultaneously on multiple processors (Correct answer)
- Concurrency requires multiple CPUs; parallelism does not
- Parallelism is single-threaded; concurrency is multi-threaded
Correct answer: Concurrency is about dealing with multiple tasks at once (possibly interleaved); parallelism is executing multiple tasks simultaneously on multiple processors
Concurrency is a design concern about structuring a program to handle multiple tasks; parallelism is physical simultaneous execution on multiple cores.
Question 24: What does the term 'API' stand for?
- Advanced Programming Interaction
- Application Programming Interface (Correct answer)
- Accessible Public Internet
- Automated Process Integration
Correct answer: Application Programming Interface
API stands for Application Programming Interface. It is a set of defined rules, protocols, and tools for building software applications. An API specifies how software components should interact, allowing different applications to communicate and share data without needing to understand each other's internal implementation details.
Question 25: What is the role of the Requirements Gathering phase in SDLC?
- Understanding user needs and system functions (Correct answer)
- Testing system performance
- Building the user interface
- Developing the system architecture
Correct answer: Understanding user needs and system functions
The Requirements Gathering phase is crucial for thoroughly understanding what the software needs to achieve from the perspective of its users and stakeholders. It involves eliciting, analyzing, and documenting all functional and non-functional requirements to ensure the developed system meets the intended purpose and user needs.
Question 26: What does the SQL keyword DISTINCT do when used in a SELECT statement?
- Sorts the result set in ascending order
- Removes duplicate rows from the query result (Correct answer)
- Limits the number of rows returned
- Filters rows based on a condition
Correct answer: Removes duplicate rows from the query result
DISTINCT instructs the database to return only unique rows, eliminating any duplicate combinations of the selected columns from the result set.
Question 27: What is the Strategy design pattern?
- A pattern for handling exceptions using policies
- A pattern that selects a network protocol at compile time
- A pattern defining a family of algorithms, encapsulating each one, and making them interchangeable (Correct answer)
- A pattern for choosing a database strategy
Correct answer: A pattern defining a family of algorithms, encapsulating each one, and making them interchangeable
The Strategy pattern lets you select an algorithm's behavior at runtime by encapsulating each variant in its own class sharing a common interface.
Question 28: Which data structure is most suitable for implementing a LIFO (Last In, First Out) principle?
- Array
- Linked List
- Queue
- Stack (Correct answer)
Correct answer: Stack
A Stack is a linear data structure that strictly follows the Last In, First Out (LIFO) principle. This means the last element added to the stack is always the first one to be removed. Operations like `push` (adding an element) and `pop` (removing an element) occur only at one end, known as the 'top' of the stack.
Question 29: What is a condition variable used for in threading?
- Allowing threads to block and wait until a specific condition becomes true, then be notified to wake up (Correct answer)
- Synchronizing file I/O across threads
- Checking CPU load before creating new threads
- Storing per-thread configuration flags
Correct answer: Allowing threads to block and wait until a specific condition becomes true, then be notified to wake up
Condition variables work with a mutex to efficiently block a thread until another thread signals that a condition it needs has changed.
Question 30: Which of the following is an example of a divide-and-conquer algorithm?
- Merge Sort (Correct answer)
- Insertion Sort
- Linear Search
- Bubble Sort
Correct answer: Merge Sort
Merge Sort is a classic example of a divide-and-conquer algorithm. It works by recursively dividing an unsorted list into 'n' sublists, each containing one element (the 'divide' step). Then, it repeatedly merges sublists to produce new sorted sublists until there is only one sorted list remaining (the 'conquer' step).
Question 31: Which property of the ACID model ensures that a transaction either fully completes or has no effect on the database?
- Isolation
- Durability
- Consistency
- Atomicity (Correct answer)
Correct answer: Atomicity
Atomicity guarantees that a transaction is treated as a single unit — it either commits entirely or rolls back entirely, leaving no partial state.
Question 32: What is the role of a circuit breaker pattern in distributed systems?
- Detecting repeated failures in a service call and short-circuiting requests to prevent cascading failures (Correct answer)
- Encrypting communication between microservices
- Cutting power to a server when it overheats
- Balancing load across multiple service instances
Correct answer: Detecting repeated failures in a service call and short-circuiting requests to prevent cascading failures
The circuit breaker pattern stops calling a failing service temporarily, allowing it to recover and preventing the caller from blocking on timeouts.
Question 33: What is the space complexity of a recursive algorithm?
- O(n^2)
- O(1)
- O(log n)
- O(n) (Correct answer)
Correct answer: O(n)
The space complexity of a recursive algorithm is typically O(n), where 'n' often represents the depth of the recursion. This is because each recursive call adds a new frame to the call stack to store local variables, parameters, and the return address. In the worst case, the stack space can grow proportionally to the input size or recursion depth.
Question 34: Which of the following is a non-linear data structure?
- Linked List
- Stack
- Array
- Binary Tree (Correct answer)
Correct answer: Binary Tree
A Binary Tree is a non-linear data structure where each node has at most two children, typically referred to as the left child and the right child. Unlike linear structures like arrays, linked lists, and stacks, which arrange data sequentially, a binary tree organizes data hierarchically in a branching fashion.
Question 35: What is Cross-Site Scripting (XSS)?
- Sending HTTP requests from one domain to another
- An attack where malicious scripts are injected into web pages viewed by other users (Correct answer)
- Cross-browser compatibility testing
- A technique for optimizing JavaScript execution
Correct answer: An attack where malicious scripts are injected into web pages viewed by other users
XSS injects malicious client-side scripts into pages, allowing attackers to steal cookies, session tokens, or redirect users.
Question 36: What is CQRS (Command Query Responsibility Segregation)?
- A caching strategy using separate read replicas
- Using different databases for development and production
- A pattern that separates read (query) and write (command) operations into distinct models (Correct answer)
- Separating SELECT and INSERT SQL statements into different files
Correct answer: A pattern that separates read (query) and write (command) operations into distinct models
CQRS uses separate models for updating and reading data, enabling independent optimization, scaling, and even different storage for each side.
Question 37: In a relational database, what does a composite key mean?
- A key that references multiple foreign tables simultaneously
- An automatically generated surrogate key
- A primary key consisting of two or more columns combined to uniquely identify a row (Correct answer)
- A key derived from a formula or expression
Correct answer: A primary key consisting of two or more columns combined to uniquely identify a row
A composite key uses two or more columns together as the primary key, where neither column alone is sufficient to uniquely identify a row but the combination is.
Question 38: What is a thread pool and why is it used?
- A memory region shared between threads
- A collection of pre-created threads that execute submitted tasks, avoiding the overhead of creating and destroying threads for each task (Correct answer)
- A mechanism to limit heap allocation per thread
- A list of blocked threads waiting on a lock
Correct answer: A collection of pre-created threads that execute submitted tasks, avoiding the overhead of creating and destroying threads for each task
Thread pools reuse a fixed set of worker threads to execute many tasks, reducing the expensive cost of thread creation for short-lived work.
Question 39: Which of the following is a common type of code testing?
- System testing
- All of the above (Correct answer)
- Unit testing
- Integration testing
Correct answer: All of the above
Unit testing, integration testing, and system testing are all distinct and common types of code testing, each serving a specific purpose in the software development lifecycle. Unit testing verifies individual components in isolation, integration testing checks the interactions between modules, and system testing evaluates the complete, integrated system. Together, they provide comprehensive coverage of the software's functionality and quality.
Question 40: What is the primary goal of code testing?
- To reduce the code’s size.
- To identify errors and validate functionality (Correct answer)
- To make the code more readable.
- To improve the software’s user interface.
Correct answer: To identify errors and validate functionality
The primary goal of code testing is to systematically evaluate software to identify defects, errors, or bugs that could lead to incorrect behavior. By validating that the code performs its intended functions according to specifications, testing ensures the software's quality, reliability, and adherence to requirements. This process is crucial for delivering stable and functional applications.
C++ Certified Professional Programmer (CPP)
The CPP certification validates advanced C++ programming skills including STL containers, algorithms, templates, smart pointers, memory management, and modern C++ language features. It is administered by the C++ Institute (OpenEDG).
Exam Rules
- You can skip questions and return to them later
- Flag questions for review before submitting
- No feedback shown until you submit the entire exam
- Unanswered questions count as wrong — answer everything
- 10 pretest questions are mixed in and don't affect your score
- Timer auto-submits when time runs out
- Your progress is auto-saved every 30 seconds
These practice questions were written with AI tools. They are not real exam questions. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy