C++ Certified Professional Programmer (CPP) — Questions and Answers
Question 1: What is memoization in the context of performance optimization?
- Pre-allocating memory at application start
- Profiling memory usage at runtime
- Caching the results of expensive function calls and returning the cached result for the same inputs (Correct answer)
- Storing program state to disk for crash recovery
Correct answer: Caching the results of expensive function calls and returning the cached result for the same inputs
Memoization avoids redundant computation by storing previously computed results, trading memory for speed.
Question 2: What is the Repository pattern?
- A pattern for organizing microservice APIs
- A version control strategy for code
- An abstraction layer over data access logic that provides a collection-like interface for accessing domain objects (Correct answer)
- A pattern for caching database queries
Correct answer: An abstraction layer over data access logic that provides a collection-like interface for accessing domain objects
The Repository pattern decouples business logic from data access concerns, making it easier to swap data sources and write unit tests.
Question 3: What is the time complexity of an algorithm that performs a linear search in an unsorted array?
- O(log n)
- O(1)
- O(n^2)
- O(n) (Correct answer)
Correct answer: O(n)
The time complexity of a linear search in an unsorted array is O(n), which stands for 'Order of n'. In the worst-case scenario, the algorithm might have to check every single element in the array until the target is found or the end is reached. Therefore, the time taken grows linearly with the number of elements 'n'.
Question 4: A table is in Third Normal Form (3NF) if it is in 2NF and contains no:
- Partial dependencies
- Multi-valued attributes
- Repeating groups
- Transitive dependencies (Correct answer)
Correct answer: Transitive dependencies
3NF requires the table to be in 2NF and that no non-key attribute depends transitively on the primary key (i.e., no non-key → non-key dependencies).
Question 5: What is defensive programming?
- Writing code that anticipates and handles invalid inputs, unexpected states, and failures gracefully (Correct answer)
- Encrypting all code before deployment
- Using defensive copies of all data structures
- Protecting code with software patents
Correct answer: Writing code that anticipates and handles invalid inputs, unexpected states, and failures gracefully
Defensive programming assumes that inputs may be invalid and external systems may fail, adding validation and error handling proactively.
Question 6: Which of the following is an object-oriented programming language?
- Assembly
- Python (Correct answer)
- Fortran
- C
Correct answer: Python
Python is an object-oriented programming (OOP) language because it supports core OOP concepts such as classes, objects, inheritance, polymorphism, and encapsulation. Developers can define custom data types and their behaviors, making code modular and reusable. In contrast, C, Assembly, and Fortran are primarily procedural or low-level languages without native OOP paradigms.
Question 7: Which of the following best explains why using SELECT * in production queries is generally discouraged?
- SELECT * is not valid standard SQL syntax
- It retrieves all columns including unused ones, increasing network payload and breaking code if the schema changes (Correct answer)
- It automatically locks the table for writes during execution
- Databases do not support indexing on SELECT * queries
Correct answer: It retrieves all columns including unused ones, increasing network payload and breaking code if the schema changes
SELECT * retrieves every column even if most are unused, wastes bandwidth and memory, and silently breaks application code if columns are added, removed, or reordered.
Question 8: What does O(log n) time complexity represent?
- Linear growth
- Quadratic growth
- Logarithmic growth (Correct answer)
- Exponential 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 9: Which of the following is a non-linear data structure?
- Stack
- Linked List
- 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 10: Which of the following is a common type of code testing?
- System testing
- All of the above (Correct answer)
- Integration testing
- Unit 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 11: Which normal form eliminates multi-valued dependencies, where one attribute independently determines two or more other attributes?
- Second Normal Form (2NF)
- Fourth Normal Form (4NF) (Correct answer)
- Third Normal Form (3NF)
- Boyce-Codd Normal Form (BCNF)
Correct answer: Fourth Normal Form (4NF)
4NF extends BCNF by requiring that a table have no non-trivial multi-valued dependencies — cases where one key independently determines two separate sets of values.
Question 12: What is the primary goal of code testing?
- To reduce the code’s size.
- To make the code more readable.
- To improve the software’s user interface.
- To identify errors and validate functionality (Correct answer)
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.
Question 13: What is input validation and why is it critical for secure software?
- Logging all user inputs to a database
- Encrypting user inputs before storage
- Checking that user inputs match expected formats and ranges to prevent injection attacks and data corruption (Correct answer)
- Limiting the length of variable names in code
Correct answer: Checking that user inputs match expected formats and ranges to prevent injection attacks and data corruption
Input validation rejects or sanitizes unexpected inputs at system boundaries, preventing SQL injection, XSS, and buffer overflow attacks.
Question 14: What is the Java Memory Model (JMM) relevant to CPP-level knowledge?
- It specifies rules about when writes by one thread become visible to other threads (Correct answer)
- It dictates the maximum number of threads allowed
- It defines how Java allocates heap vs stack memory
- It controls garbage collection frequency
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 15: What is a semaphore in concurrent programming?
- A signaling mechanism that controls access to a limited number of resources using a counter (Correct answer)
- A hardware interrupt handler
- A type of thread pool
- A way to terminate threads gracefully
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 16: Which of the following is a framework used for building mobile applications?
- Django
- Flutter (Correct answer)
- Ruby on Rails
- Spring Boot
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 17: Which SQL clause is used to filter results after an aggregate function has been applied?
- GROUP BY
- ORDER BY
- WHERE
- HAVING (Correct answer)
Correct answer: HAVING
HAVING filters rows after GROUP BY aggregation, whereas WHERE filters rows before aggregation occurs.
Question 18: What is secure coding practice regarding sensitive data in logs?
- Encrypt log files after writing
- Never log passwords, tokens, credit card numbers, or PII; mask or omit sensitive fields (Correct answer)
- Store logs in a separate database
- Log all data for maximum debuggability
Correct answer: Never log passwords, tokens, credit card numbers, or PII; mask or omit sensitive fields
Logging sensitive data creates a secondary attack surface; if logs are exfiltrated, attackers gain credentials or personal information.
Question 19: What is a 'static' method in OOP?
- A method belonging to the class rather than any instance (Correct answer)
- A method that always returns void
- A method with no parameters
- A method that cannot be overridden
Correct answer: A method belonging to the class rather than any instance
Static methods belong to the class itself and can be called without creating an instance of the class.
Question 20: What is the space complexity of a recursive algorithm?
- O(log n)
- O(1)
- O(n^2)
- 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 21: What is a breakpoint in debugging?
- A method for optimizing the code.
- A point where the code execution is paused (Correct answer)
- A piece of code that automatically fixes errors.
- A tool used to measure performance.
Correct answer: A point where the code execution is paused
In debugging, a breakpoint is a deliberate stopping point or pause inserted into the code by the developer. When the program's execution reaches a breakpoint, it temporarily halts, allowing the programmer to inspect the program's state, including variable values, memory contents, and the call stack, at that precise moment. This pause is crucial for understanding program flow and identifying the source of errors.
Question 22: What is the producer-consumer pattern?
- A concurrency pattern where producers add work to a shared queue and consumers process items from it (Correct answer)
- A UI pattern separating data creation from display
- A network pattern for request-response communication
- A memory pattern alternating allocation and deallocation
Correct answer: A concurrency pattern where producers add work to a shared queue and consumers process items from it
The producer-consumer pattern decouples work generation from processing using a thread-safe buffer, enabling independent scaling of each side.
Question 23: What is branch prediction and why does it impact CPU performance?
- Preloading disk blocks before they are needed
- Predicting which network branch to route data through
- A CPU optimization that guesses the outcome of conditional branches to execute instructions speculatively (Correct answer)
- Choosing the fastest algorithm branch at compile time
Correct answer: A CPU optimization that guesses the outcome of conditional branches to execute instructions speculatively
CPUs use branch prediction to speculatively execute code ahead of resolving a branch, and mispredictions cause costly pipeline flushes.
Question 24: What is the primary use case of a hash table?
- Direct access to data using a key (Correct answer)
- Recursively sorting data
- Storing data in sorted order
- Linking data elements together
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 25: What does an ORM (Object-Relational Mapper) primarily accomplish in application development?
- Optimizes SQL query execution plans automatically
- Maps database tables to programming language objects, eliminating manual SQL (Correct answer)
- Converts SQL schemas to NoSQL document formats
- Provides a caching layer in front of the database
Correct answer: Maps database tables to programming language objects, eliminating manual SQL
An ORM bridges the gap between object-oriented code and relational databases by automatically translating between objects/classes and database rows/tables.
Question 26: What is the role of the 'this' keyword in OOP languages?
- Refers to a static context
- Refers to the parent class
- Refers to the current object instance (Correct answer)
- Creates a new object
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 27: Which data structure is most suitable for implementing a LIFO (Last In, First Out) principle?
- Queue
- Array
- Linked List
- 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 28: Which database isolation level prevents dirty reads but still allows non-repeatable reads?
- REPEATABLE READ
- SERIALIZABLE
- READ COMMITTED (Correct answer)
- READ UNCOMMITTED
Correct answer: READ COMMITTED
READ COMMITTED ensures a transaction only reads data that has been committed, preventing dirty reads, but another transaction can still modify and commit rows between reads within the same transaction.
Question 29: What is the difference between an interface and an abstract class?
- Abstract classes can have state and partial implementation; interfaces define contracts with no (or default) implementation (Correct answer)
- Abstract classes support multiple inheritance; interfaces do not
- Interfaces can have method implementations; abstract classes cannot
- They are identical concepts in modern OOP
Correct answer: Abstract classes can have state and partial implementation; interfaces define contracts with no (or default) implementation
Abstract classes can contain fields and method bodies while interfaces define a contract that implementing classes must fulfill.
Question 30: What is a service mesh in microservices architecture?
- A shared database used by all microservices
- A dedicated infrastructure layer handling service-to-service communication, including load balancing, auth, and observability (Correct answer)
- A pattern for organizing microservice code repositories
- A shared API gateway for all external traffic
Correct answer: A dedicated infrastructure layer handling service-to-service communication, including load balancing, auth, and observability
A service mesh (like Istio or Linkerd) injects sidecar proxies alongside services to manage cross-cutting communication concerns transparently.
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