readyforhires

Intermediate C++ test (Intermediate)

30 questions · 35 minutes · Free

OOP, templates, STL algorithms and RAII.

Take the Intermediate C++ test

What it covers

Interview format

Earn a certificate

The Intermediate C++ test is one of the 6 tests of the Automotive Embedded Engineer learning path. Pass it and the other 5 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, 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 Intermediate 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 of the following accurately describes a variadic template in C++?

    1. A variadic template is a C++ feature that restricts a function or class template to a single type of argument, but allows for a variable number of arguments.
    2. A variadic template allows a function or class template to accept a variable number of arguments of different types, which are represented using parameter packs.
    3. A variadic template is a C++ feature used to enforce a specific number of arguments for a function or class template, regardless of their types.
    4. A variadic template is a way to define a template that can only accept a fixed number of arguments, but with varying types.

    Answer: B. A variadic template allows a function or class template to accept a variable number of arguments of different types, which are represented using parameter packs.

    A variadic template is a C++ feature that allows a function or class template to accept a variable number of arguments of different types. These arguments are represented using parameter packs, which are denoted by an ellipsis (`...`). Variadic templates are commonly used in scenarios where the number of arguments is not known at compile time, such as in implementations of `std::tuple`, `std::make_pair`, and other generic utilities.

  2. Consider the following C++ code: class A { public: virtual void show() { cout << "A::show()" << endl; } }; class B : public A { public: void show() override { cout << "B::show()" << endl; } }; int main() { A* obj = new B(); obj->show(); return 0; } What will be the output of the program and why?

    1. The output will be 'A::show()'
    2. The output will be 'A::show() followed by B::show()'
    3. The output will be 'B::show() followed by A::show()'
    4. The output will be 'B::show()'

    Answer: D. The output will be 'B::show()'

    When a virtual function is overridden in a derived class, calling the function through a base class pointer will invoke the derived class's implementation due to dynamic dispatch. In this case, since 'B::show()' overrides 'A::show()', the output will be 'B::show()'.

  3. What is the primary advantage of using `emplace_back` over `push_back` in STL containers like `std::vector`?

    1. It moves the object into the container, leaving the original in an unspecified state.
    2. It copies the object into the container and then deallocates the original.
    3. It creates a temporary object and then swaps it with the container's internal storage.
    4. It constructs the object in-place, avoiding unnecessary copies or moves.

    Answer: D. It constructs the object in-place, avoiding unnecessary copies or moves.

    The `emplace_back` method constructs the object directly within the container's memory, which is more efficient than `push_back` because it avoids creating a temporary object and then moving or copying it into the container.

  4. What is true about a class that contains a pure virtual function?

    1. The class is abstract but can be instantiated using a pointer.
    2. The class is not abstract but can be used as a base class.
    3. The class is abstract and cannot be instantiated directly.
    4. The class can be instantiated directly.

    Answer: C. The class is abstract and cannot be instantiated directly.

    A class with at least one pure virtual function (declared as `virtual void f() = 0;`) is considered abstract. Abstract classes cannot be instantiated directly because they have pure virtual functions that have no implementation. However, they can be used as base classes for derived classes that implement all pure virtual functions.

  5. What is the behavior of a pure virtual function in a C++ base class?

    1. It can be instantiated directly and does not require overriding in derived classes.
    2. It is only allowed in private access specifiers.
    3. It is automatically implemented by the compiler in derived classes.
    4. It cannot be instantiated directly and must be overridden in derived classes.

    Answer: D. It cannot be instantiated directly and must be overridden in derived classes.

    A pure virtual function is declared with = 0 in the base class. It makes the class abstract, meaning it cannot be instantiated directly. Derived classes must override the pure virtual function to provide an implementation, otherwise they are also abstract.

Frequently asked questions

How many questions are in the Intermediate C++ test?
30 questions (18 multiple choice, 9 multi-answer, 3 predict-the-output), with 35 minutes to answer them.
What does the Intermediate C++ test cover?
Inheritance and virtual functions, Templates, STL containers and algorithms, RAII and smart pointers, Operator overloading.
Is the Intermediate C++ test free?
Yes. It is free to take with a readyforhires account.
What level is the Intermediate C++ test?
Intermediate, in Backend.

More Backend tests

Roles that test these skills

Companies that test these skills

All practice tests · All Backend tests

Last updated