🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Memory and Smart Pointers: all 10 questions

Quiz: Memory and Smart Pointers · Question 5 of 10

What does this print? (code)

What does this print?

#include <iostream>
#include <memory>
using namespace std;
int main() {
    auto a = make_shared<int>(5);
    auto b = a;
    auto c = b;
    cout << a.use_count();
    return 0;
}
  1. A.1
  2. B.2
  3. C.3
  4. D.5
Answer & explanation

Correct answer: 3

Three shared_ptrs own the same int.

Can you get the rest right without peeking?

Take the timed Quiz: Memory and Smart Pointers quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →