Quiz on Smart Pointers in C++

This quiz on Smart Pointers in C++ is designed for placement tests and job interviews. It is a valuable resource for freshers, including Engineering Students, MCA students, Computer and IT Engineers, and others preparing for campus placements.

Our MCQ on Smart Pointers covers different concepts related to smart pointers and their uses. We will regularly update the quiz list with new questions in a random sequence to provide a fresh experience each time you take it.

We have also published a blog post containing short questions on pointers. You can check out this blog post for additional practice: “Pointer interview questions in C/C++“.

 

Guideline of Smart Pointers Quiz:

This MCQ on Smart Pointers is intended to check your knowledge. It takes 3 minutes to pass the Smart Pointer MCQ. If you don’t finish the quiz on Smart Pointers within the mentioned time, all the unanswered questions will count as wrong. You can miss the questions by clicking the “Next” button and return to the previous questions by the “Previous” button. Every unanswered question will count as wrong. MCQ on Smart Pointers has randomization features, giving you a new question set at every attempt.

In this Quiz on Smart Pointers, we have also implemented a feature that does not allow the user to see the next question or finish the quiz without attempting the current Quiz.

0 votes, 0 avg

You have 3 minutes to take the Quiz on Smart Pointers

Your time has been Over.


MCQ On Smart Pointers

MCQ On Smart Pointers

1 / 10

What does std::make_shared do?

2 / 10

Given the following code, what will be the output?

#include <memory>
#include <iostream>

class Test {
public:
  Test() {
    std::cout << "Constructed\n";
  }
  ~Test() {
    std::cout << "Destructed\n";
  }
};

void foo(std::shared_ptr<Test> ptr) {
  std::cout << "Inside foo\n";
}

int main() {
  std::shared_ptr<Test> sp = std::make_shared<Test>();
  foo(sp);
  std::cout << "End of main\n";
  return 0;
}

 

 

3 / 10

Which of the following is true about std::unique_ptr?

4 / 10

Which header file must be included to use std::unique_ptr?

5 / 10

What is the primary purpose of std::weak_ptr?

6 / 10

Which of the following is not a characteristic of std::unique_ptr?

7 / 10

Which smart pointer would you use for single ownership of a resource that needs to be transferred between functions?

8 / 10

Which of the following is true about std::weak_ptr?

9 / 10

What happens when the last std::shared_ptr owning a resource is destroyed?

10 / 10

How do you release the ownership of the resource managed by a std::unique_ptr without deleting it?

Your score is

The average score is 80%

0%

Recommended Articles for you: