← Back to Pointers
Question 705
Hand Off Ownership with std::move
Hand Off Ownership with std::move
Read one integer from standard input. Create aunique_ptr<int>namedfirstthat owns a heap int holding that number and print its value. Then move ownership into a secondunique_ptr<int>namedsecondusingstd::move, and print the value throughsecondfollowed by whether each pointer is now null. For the input9the program prints exactly the output shown in Expected Output. The last two lines print the result of a comparison (1for true,0for false), never a pointer itself. Do not writedeleteand do not use a rawnew.
Expected Output:
first holds: 9 after move second holds: 9 first is null: 1 second is null: 0
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.