readyforhires

Advanced C++ test (Advanced)

40 questions · 40 minutes · ₹13

Move semantics, template metaprogramming, concurrency and modern C++.

Take the Advanced C++ test

Prices in Indian rupees (INR).

What it covers

Interview format

Earn a certificate

The Advanced C++ test is one of the 7 tests of the Automotive Embedded Engineer: Advanced learning path. Pass it and the other 6 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.

Sample learning path certificate for Automotive Embedded Engineer: Advanced, made out to “Your name” and marked SAMPLE
Pass with 70% or more to earn a verifiable certificate. This is a sample: yours carries your name, the date you earned it and its own verify code.

Sample questions

5 sample questions from the Advanced C++ test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.

  1. Which statement accurately describes coroutines and their use cases compared to alternatives like threads or callbacks?

    1. Coroutines are equivalent to threads and provide no additional benefits in terms of asynchronous programming.
    2. Coroutines allow for cooperative multitasking and can be paused and resumed, making them ideal for asynchronous I/O and long-running operations. Alternatives like threads are better for CPU-bound tasks that require parallelism.
    3. Coroutines are a deprecated feature in C++ and should be avoided in favor of threads or callbacks.
    4. Coroutines are only useful for CPU-bound tasks and are less efficient than threads for asynchronous I/O.

    Answer: B. Coroutines allow for cooperative multitasking and can be paused and resumed, making them ideal for asynchronous I/O and long-running operations. Alternatives like threads are better for CPU-bound tasks that require parallelism.

    Coroutines are well-suited for asynchronous operations due to their ability to pause and resume execution, which minimizes resource usage and improves efficiency. Threads, on the other hand, are better for CPU-bound tasks that require parallelism. Callbacks are suitable for simple asynchronous operations but can lead to callback hell. Promises are more related to futures and not directly tied to coroutine behavior.

  2. Which statement correctly describes the purpose and behavior of std::move in C++?

    1. std::move is a utility that is only required when using custom move constructors in C++17.
    2. std::move is used to explicitly cast an lvalue to an xvalue, enabling move semantics; it does not perform the move itself.
    3. std::move is used to convert an rvalue to an lvalue, allowing it to be bound to lvalue references.
    4. std::move is a function that performs the move operation by transferring ownership of resources.

    Answer: B. std::move is used to explicitly cast an lvalue to an xvalue, enabling move semantics; it does not perform the move itself.

    std::move is a cast to T&&, which allows the move constructor or move assignment operator to be selected. It does not perform the move directly; the actual move is handled by the move constructor/assignment. The other options are either incorrect or describe other aspects of move semantics.

  3. In a project that involves asynchronous I/O operations, which of the following is the most appropriate approach to manage asynchronous tasks using coroutines?

    1. Use a traditional callback-based approach for all asynchronous I/O operations.
    2. Use a coroutine to handle asynchronous I/O operations and yield control back to the event loop during long-running tasks.
    3. Use std::async with launch::async for all asynchronous operations.
    4. Avoid using coroutines and rely on threads for all asynchronous tasks.

    Answer: B. Use a coroutine to handle asynchronous I/O operations and yield control back to the event loop during long-running tasks.

    Coroutines are ideal for asynchronous code in C++ because they allow non-blocking operations to be written in a synchronous style. By using `co_await`, coroutines can yield control back to the event loop during I/O operations, enabling the program to handle other tasks concurrently. This is more efficient and easier to manage than traditional callback-based approaches.

  4. Which of the following correctly demonstrates perfect forwarding of an argument x of type T in a function template?

    1. std::forward<decltype(x)>(x)
    2. std::forward<T>(x)
    3. std::forward(x)
    4. std::forward<void>(x)

    Answer: B. std::forward<T>(x)

    When using perfect forwarding, the correct way to forward an argument is with std::forward<T>(x), where T is the type of the argument. This preserves the value category (lvalue or rvalue) of the original argument, enabling efficient move operations when appropriate. Using std::forward<void>(x) or std::forward<decltype(x)>(x) would be incorrect in this context as they do not correctly capture the type of the argument.

  5. What is the issue with the following C++20 coroutine code that prevents it from functioning as asynchronous code? Consider the following function: `std::suspend_always operator co_await() { return {}; }`.

    1. The coroutine should use a std::future object to return results asynchronously.
    2. The coroutine is missing a co_await or co_yield statement, which is required for asynchronous execution.
    3. The coroutine should use std::async instead of coroutines for asynchronous execution.
    4. The coroutine is not marked with the [[nodiscard]] attribute, which is required for coroutines.

    Answer: B. The coroutine is missing a co_await or co_yield statement, which is required for asynchronous execution.

    In C++20 coroutines, a coroutine function must contain at least one co_await or co_yield statement to be considered asynchronous. Without these, the coroutine behaves like a regular function and does not yield control back to the caller, which defeats the purpose of asynchronous programming.

Frequently asked questions

How many questions are in the Advanced C++ test?
40 questions (24 multiple choice, 12 multi-answer, 4 predict-the-output), with 40 minutes to answer them.
What does the Advanced C++ test cover?
Move semantics and perfect forwarding, Template metaprogramming and concepts, Concurrency and the memory model, Undefined behaviour, C++17/20 features.
Is the Advanced C++ test free?
It costs ₹13 a test, paid per test with no subscription. Prices in Indian rupees (INR).
What level is the Advanced C++ test?
Advanced, in Backend.

More Backend tests

Roles that test these skills

Companies that test these skills

All practice tests · All Backend tests

Last updated