Skip to content
codinganthem

C++ skill check

Test your C++: references and pointers, RAII, virtual functions, templates, the STL, and move semantics, with snippets that check what really happens at run time.

15

Questions

14 min

Timer can't pause

Multiple choice

C++20

Choose a level

Question type

About 40% code reading

Topics

  • Types and references
  • Pointers and memory
  • Classes and RAII
  • Inheritance and virtual functions
  • Templates
  • STL containers
  • Move semantics
  • Undefined behaviour

Do

Use scratch paper or a notepad to work things out. Skip a question and come back to it later.

Don't

Run the code or look up answers during the check. Open the check in more than one tab or window.

Easy · Mixed · 15 questions · 14 min

By starting, you agree to the Terms and Privacy Policy.

Start practice

Practice checks each answer as you go, with an explanation. The exam is checked when you submit; 9 of 15 passes and earns a certificate.

Checking your levels…

Certificates come from the certified exam: pass with 9 of 15 while signed in. View a sample certificate.

Sample C++ questions with answers

These are never used in a check, so seeing their answers here won't give anything away.

  1. Question 1 · Easy · Types and references

    Which statement correctly describes the behavior of an lvalue reference in C++?
    1. A.It acts as an alias to an existing object and must be initialized when declared.
    2. B.It can be reseated to refer to a different object at any time after initialization.
    3. C.It automatically allocates a separate copy of the referenced variable on the stack.
    4. D.It can bind directly to a non-const temporary object of the same type.
    Show answer

    A. It acts as an alias to an existing object and must be initialized when declared.

    In C++, an lvalue reference (T&) is an alias for an existing object and cannot be left uninitialized. Once bound to an object, it cannot be reseated to point to another object.
  2. Question 2 · Easy · Pointers and memory

    What is the primary difference between std::unique_ptr and std::shared_ptr?
    1. A.std::unique_ptr requires manual invocation of delete, whereas std::shared_ptr deletes automatically.
    2. B.std::unique_ptr enforces exclusive ownership of a resource, whereas std::shared_ptr shares ownership via reference counting.
    3. C.std::unique_ptr allocates memory on the stack, whereas std::shared_ptr allocates memory on the heap.
    4. D.std::unique_ptr can be copied to multiple threads safely, whereas std::shared_ptr is strictly single-threaded.
    Show answer

    B. std::unique_ptr enforces exclusive ownership of a resource, whereas std::shared_ptr shares ownership via reference counting.

    std::unique_ptr represents exclusive ownership and cannot be copied, only moved. std::shared_ptr maintains a reference count so that the managed object is destroyed only when the last owning pointer is destroyed.
  3. Question 3 · Moderate · Classes and RAII

    Under the Rule of Five, if a class explicitly declares a user-defined destructor, what happens to the default move operations (move constructor and move assignment)?
    1. A.They are implicitly generated only if all member variables are trivially copyable.
    2. B.They are implicitly declared as default and perform memberwise moves.
    3. C.They are not declared, and attempts to move the object fall back to copy operations.
    4. D.They are implicitly deleted, causing a compile error when attempting to move.
    Show answer

    C. They are not declared, and attempts to move the object fall back to copy operations.

    Declaring a user-provided destructor inhibits the implicit generation of move operations; overload resolution falls back to copying if copy operations are available.
  4. Question 4 · Advanced · Move semantics

    Why does std::vector::push_back or reallocation choose an element's copy constructor instead of its move constructor when the move constructor is not marked noexcept?
    1. A.To uphold the strong exception guarantee, ensuring the vector can remain in its original state if an element copy/move throws.
    2. B.Non-noexcept move constructors cannot be detected via type traits at compile time, defaulting std::move_if_noexcept to copy.
    3. C.Moving without noexcept forces the compiler to emit exception tables that double the binary footprint of container instantiations.
    4. D.The standard library explicitly bans moving types that might throw to prevent memory leaks in the allocator.
    Show answer

    A. To uphold the strong exception guarantee, ensuring the vector can remain in its original state if an element copy/move throws.

    If an exception is thrown mid-reallocation while moving elements, the source vector's previous elements have already been mutated and cannot be restored, violating the strong exception guarantee. Using copy construction allows the original vector to be left intact if an exception occurs.

How scoring and certificates work

  • Each check has 15 multiple-choice questions with one correct answer, and one timer for the whole check. A question you leave unanswered scores nothing.
  • Practice is free without an account and shows whether each answer is right as you go, with an explanation.
  • The certified exam is scored when you submit. 60% passes, which is 9 of 15. Easy unlocks Moderate, and Moderate unlocks Advanced.
  • Passing the exam while signed in earns a free certificate, valid for one year, with its own verification page. See a sample certificate.