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
- Storing program state to disk for crash recovery
- Profiling memory usage at runtime
- Caching the results of expensive function calls and returning the cached result for the same inputs (Correct answer)
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: Which data structure is most suitable for implementing a LIFO (Last In, First Out) principle?
- Stack (Correct answer)
- Array
- Linked List
- Queue
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 3: Which of the following is a feature of the Python programming language?
- Low-level language
- Compulsory type declaration
- Used only for web development
- Dynamic typing (Correct answer)
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 4: What is a thread pool and why is it used?
- A mechanism to limit heap allocation per thread
- A list of blocked threads waiting on a lock
- 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)
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 5: Which SQL JOIN returns all rows from the left table and matching rows from the right table, with NULLs for non-matching right rows?
- RIGHT OUTER JOIN
- INNER JOIN
- LEFT OUTER JOIN (Correct answer)
- FULL 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 6: What is the difference between a framework and a library?
- A framework is free to use, but libraries are not
- A library is always larger than a framework
- A framework calls the code written by the developer, while a library is called by the developer (Correct answer)
- A framework only works in one programming language
Correct answer: A framework calls the code written by the developer, while a library is called by the developer
The key difference lies in the 'Inversion of Control' principle: a framework dictates the application's flow and calls the developer's code at specific points. Conversely, a library is a collection of functions or modules that the developer explicitly calls and integrates into their application as needed. Frameworks provide a complete structure, while libraries offer specific functionalities.
Question 7: What is SQL injection?
- An error caused by missing database indexes
- Storing SQL queries in a database
- A technique for optimizing SQL query performance
- An attack where malicious SQL code is inserted into input fields to manipulate the database (Correct answer)
Correct answer: An attack where malicious SQL code is inserted into input fields to manipulate the database
SQL injection exploits unsanitized user input concatenated directly into SQL queries, allowing attackers to read, modify, or delete data.
Question 8: What is the Java Memory Model (JMM) relevant to CPP-level knowledge?
- It controls garbage collection frequency
- It dictates the maximum number of threads allowed
- 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)
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 9: Which database isolation level prevents dirty reads but still allows non-repeatable reads?
- READ UNCOMMITTED
- READ COMMITTED (Correct answer)
- SERIALIZABLE
- REPEATABLE READ
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 10: What is the Command design pattern?
- A pattern for issuing OS shell commands from code
- A pattern that encapsulates a request as an object, enabling undo/redo, queuing, and logging of operations (Correct answer)
- A pattern for routing commands to the correct handler
- A pattern that prevents unauthorized method calls
Correct answer: A pattern that encapsulates a request as an object, enabling undo/redo, queuing, and logging of operations
The Command pattern wraps a request with all necessary information as an object, decoupling the sender from the receiver.
Question 11: A correlated subquery differs from a regular subquery in that it:
- References a column from the outer query and re-executes for each outer row (Correct answer)
- Returns multiple result sets instead of one
- Always executes faster than a JOIN
- Can only be used in the SELECT clause
Correct answer: References a column from the outer query and re-executes for each outer row
A correlated subquery references a column from the outer query, causing it to be re-evaluated once per row of the outer query rather than once total.
Question 12: What is the purpose of code signing?
- Obfuscating code to prevent reverse engineering
- Compressing executables for faster distribution
- Adding copyright comments to source files
- Applying a digital signature to code so recipients can verify its authenticity and integrity (Correct answer)
Correct answer: Applying a digital signature to code so recipients can verify its authenticity and integrity
Code signing uses a private key to sign binaries; users verify with the public key that the software hasn't been tampered with and comes from a trusted source.
Question 13: What is thread-local storage (TLS)?
- A fast per-thread heap allocator
- Shared memory accessible only from threads within the same process
- A mechanism providing each thread with its own private copy of a variable (Correct answer)
- Storage for thread stack frames
Correct answer: A mechanism providing each thread with its own private copy of a variable
Thread-local storage gives each thread its own instance of a variable, eliminating the need for synchronization on that data.
Question 14: What is the principle behind 'defense in depth' in security?
- Using multiple independent security controls so that if one layer is breached, others still protect the system (Correct answer)
- Running security scans at every build step
- Requiring multiple approvals before deploying code
- Encrypting data with multiple algorithms
Correct answer: Using multiple independent security controls so that if one layer is breached, others still protect the system
Defense in depth layers security controls (authentication, authorization, encryption, firewalls, monitoring) so no single failure exposes the entire system.
Question 15: In a relational database, what does a composite key mean?
- An automatically generated surrogate key
- A key that references multiple foreign tables simultaneously
- A key derived from a formula or expression
- A primary key consisting of two or more columns combined to uniquely identify a row (Correct answer)
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 16: Which SDLC phase involves user training and system deployment?
- Design
- Testing
- Development
- Deployment (Correct answer)
Correct answer: Deployment
The Deployment phase involves making the developed software system available to end-users in its target environment. This includes activities such as installation, configuration, data migration, and often user training. The goal is to ensure the system is fully operational and ready for use by its intended audience.
Question 17: When using a database connection pool, what happens when all connections in the pool are in use and a new request arrives?
- The request waits in a queue until a connection becomes available (Correct answer)
- A new permanent connection is created immediately
- The request is silently dropped without error
- The pool automatically doubles its maximum size
Correct answer: The request waits in a queue until a connection becomes available
Connection pools have a maximum size; when all connections are busy, incoming requests are queued and wait until a connection is released back to the pool.
Question 18: Which of the following is a non-linear data structure?
- Stack
- Binary Tree (Correct answer)
- Array
- Linked List
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 19: What is the primary purpose of an algorithm?
- To solve problems using a defined sequence of steps (Correct answer)
- To store data efficiently
- To increase the complexity of a task
- To control hardware components
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 20: Which of the following is an example of a divide-and-conquer algorithm?
- Merge Sort (Correct answer)
- Linear Search
- Insertion Sort
- 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 21: What is layered (n-tier) architecture?
- A pattern using multiple inheritance hierarchies
- Organizing code into horizontal layers (presentation, business logic, data) where each layer only communicates with adjacent layers (Correct answer)
- Running multiple copies of the same application
- Deploying application components to multiple servers
Correct answer: Organizing code into horizontal layers (presentation, business logic, data) where each layer only communicates with adjacent layers
Layered architecture separates concerns into stacked layers, promoting maintainability and testability by isolating responsibilities.
Question 22: What is the purpose of the 'synchronized' keyword in Java?
- To ensure only one thread at a time executes the marked method or block (Correct answer)
- To make a method run asynchronously
- To declare a variable as thread-local
- To start a new thread
Correct answer: To ensure only one thread at a time executes the marked method or block
The synchronized keyword in Java acquires a monitor lock on entry and releases it on exit, ensuring mutual exclusion.
Question 23: What is CQRS (Command Query Responsibility Segregation)?
- A pattern that separates read (query) and write (command) operations into distinct models (Correct answer)
- Using different databases for development and production
- A caching strategy using separate read replicas
- 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 24: Which tool is commonly used for debugging in software development?
- Compiler
- Web browser
- Text editor
- Debugger (Correct answer)
Correct answer: Debugger
A debugger is a specialized software tool specifically designed to assist programmers in the process of finding and fixing errors in their code. It provides functionalities like setting breakpoints, stepping through code execution line by line, inspecting variable values, and examining the call stack. These features make it an indispensable tool for diagnosing and resolving software defects.
Question 25: What is the principle of least privilege in security?
- Requiring administrator approval for all operations
- Giving users and programs only the minimum access rights needed to perform their tasks (Correct answer)
- Restricting access to production databases
- Granting users all permissions by default
Correct answer: Giving users and programs only the minimum access rights needed to perform their tasks
Least privilege minimizes the damage a compromised account or buggy code can do by limiting what resources it can access.
Question 26: What is the difference between parallelism and concurrency?
- They are identical concepts
- Parallelism is single-threaded; concurrency is multi-threaded
- Concurrency requires multiple CPUs; parallelism does not
- Concurrency is about dealing with multiple tasks at once (possibly interleaved); parallelism is executing multiple tasks simultaneously on multiple processors (Correct answer)
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 27: 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 28: What is the primary use case of a hash table?
- Storing data in sorted order
- Recursively sorting data
- Direct access to data using a key (Correct answer)
- 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 29: Which of the following is a common type of code testing?
- Integration testing
- Unit testing
- System testing
- All of the above (Correct answer)
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 30: What is the time complexity of an algorithm that performs a linear search in an unsorted array?
- O(log n)
- O(n^2)
- O(n) (Correct answer)
- O(1)
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 31: What is the 'Liskov Substitution Principle' (LSP)?
- High-level modules should not depend on low-level modules
- Clients should not be forced to depend on interfaces they do not use
- Every class should have only one reason to change
- Subclasses should be replaceable for their base classes without altering program correctness (Correct answer)
Correct answer: Subclasses should be replaceable for their base classes without altering program correctness
LSP states that objects of a subclass must be usable wherever their parent class is expected without breaking the application.
Question 32: Which design concept is described as 'favoring composition over inheritance'?
- Inheriting from multiple base classes
- Building complex behavior by combining simpler objects rather than extending class hierarchies (Correct answer)
- Using only static methods
- 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 33: What is the 'happens-before' relationship in concurrent programming?
- A CPU instruction reordering optimization
- A thread scheduling priority rule
- A guarantee that one operation's effects are visible to another operation (Correct answer)
- A deadlock prevention ordering
Correct answer: A guarantee that one operation's effects are visible to another operation
The happens-before relationship guarantees that memory writes visible before a synchronization point are also visible after that point to other threads.
Question 34: What is a service mesh in microservices architecture?
- 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 database used by all microservices
- 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.
Question 35: What is a binary search algorithm?
- It is a technique for sorting a binary tree
- It divides the list into two and searches through one half (Correct answer)
- It is a method to find an element in an unsorted array
- It is a method to sort elements in an array
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 36: What is defensive programming?
- Writing code that anticipates and handles invalid inputs, unexpected states, and failures gracefully (Correct answer)
- Protecting code with software patents
- Using defensive copies of all data structures
- Encrypting all code before deployment
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 37: What is the purpose of exception handling best practice of 'catching specific exceptions'?
- To handle each error type appropriately and avoid silently swallowing unexpected errors (Correct answer)
- To ensure all exceptions propagate to the top level
- To reduce the number of try-catch blocks in code
- To improve application performance by reducing exception objects
Correct answer: To handle each error type appropriately and avoid silently swallowing unexpected errors
Catching specific exception types lets you respond correctly to each situation; catching generic Exception may mask bugs by handling all errors the same way.
Question 38: What is a buffer overflow vulnerability?
- Writing more data into a buffer than it can hold, overwriting adjacent memory and potentially allowing code execution (Correct answer)
- Overflowing a Java ArrayList by adding too many elements
- Exceeding the maximum size of an integer
- Filling a database table beyond its capacity
Correct answer: Writing more data into a buffer than it can hold, overwriting adjacent memory and potentially allowing code execution
Buffer overflows in C/C++ allow attackers to overwrite return addresses or function pointers, leading to arbitrary code execution.
Question 39: In the CAP theorem for distributed databases, which two properties can be simultaneously guaranteed during a network partition?
- Availability and Durability
- Consistency and Partition Tolerance, or Availability and Partition Tolerance — but not all three (Correct answer)
- Consistency and Durability
- Consistency and Availability
Correct answer: Consistency and Partition Tolerance, or Availability and Partition Tolerance — but not all three
The CAP theorem states that during a network partition, a distributed system can guarantee either Consistency or Availability but not both; Partition Tolerance is mandatory in distributed systems.
Question 40: What is the role of the 'this' keyword in OOP languages?
- Creates a new object
- Refers to a static context
- Refers to the parent class
- Refers to the current object instance (Correct answer)
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.
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