Question 1
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
#include <memory>
int main() {
auto a = std::make_shared<int>(5);
std::cout << a.use_count();
{
auto b = a;
auto c = b;
std::cout << a.use_count();
c.reset();
std::cout << a.use_count();
}
std::cout << a.use_count() << '\n';
return 0;
}
- A 1321 Correct
- B 1331
- C 1221
- D 1320
Correct Answer: Option A
Copies add owners; reset() removes one; leaving the scope destroys b.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!