Assuming standard headers and using namespace std, what does this C++ code print? unique_ptr<int> a = make_unique<int>(5); unique_ptr<int> b = std::move(a); cout << (a == nullptr) << *b;
Correct answer A. 15
Explanation
unique_ptr cannot be copied, but it can be moved. Moving transfers ownership of the int to b and leaves a guaranteed empty (null), so a == nullptr is true and prints 1, and *b is 5. Writing unique_ptr b = a without std::move would not compile because the copy constructor is deleted.
Answer checked How we write and check questions
Discussion