Free CPA-21-02 sample questions
Try these free CPA-21-02 sample questions, each with the right answer and an explanation. They cover operator rules, pointer arithmetic and class constructors. Work through them to see whether you are ready for the associate exam or need more time with C++.
Try them in the simulator Same questions, with study, timed and flashcard modes.
Showing 10 of 20 free sample questions.
A class `DataProcessor` is designed to handle sensitive information. To log internal state for debugging purposes, a free function `logInternalState` needs access to the private members of `DataProcessor`. Which mechanism should be used to grant this access without exposing the members publicly?
What is the output of the following C++ code that demonstrates the behavior of a `switch` statement? ```cpp #include int main() { int value = 2; switch (value) { case 1: std::cout << "A"; case 2: std::cout << "B"; case 3: std::cout << "C"; break; default: std::cout << "D"; } return 0; } ```
A developer wants to use a single namespace for a collection of utility functions but also wants to provide a shorter, more convenient alias for it within a specific implementation file. Which of the following code snippets correctly defines a namespace `StringUtils` and creates an alias `SU` for it?
What is the primary difference between `delete ptr` and `delete[] ptr` when managing dynamically allocated memory?
A developer is creating a template function `processData` that should behave differently for `int` types than for all other types. Which C++ feature allows for creating a specialized implementation of a template for a specific type? (Select the best answer)
A developer is trying to implement a copy constructor for the `Widget` class. Which of the following signatures is the correct and canonical form for a copy constructor? ```cpp class Widget { private: int* data; public: // ... other members // Correct copy constructor signature? }; ```
What is the output of the following program? ```cpp #include class Base { public: virtual void print() { std::cout << "Base "; } }; class Derived : public Base { public: void print() override { std::cout << "Derived "; } }; void display(Base b) { b.print(); } int main() { Derived d; display(d); return 0; } ```
The `throw()` exception specifier, while part of older C++ standards, is deprecated in C++11 and removed in C++17. What is its modern C++ equivalent, used to specify that a function will not throw any exceptions?
What is the primary mechanism in C++ to resolve the ambiguity and state duplication caused by the 'diamond problem' in multiple inheritance? graph TD A[Base] --> B[Derived1] A --> C[Derived2] B --> D[FinalDerived] C --> D
10 more free samples are waiting
Create a free account to unlock the whole CPA-21-02 sample bank, or get full access to all 275 practice questions in the simulator.