CJCoding With Joseph
15free / daySign inCreate account

Hand Off Ownership with std::move

Read one integer from standard input. Create a unique_ptr<int> named first that owns a heap int holding that number and print its value. Then move ownership into a second unique_ptr<int> named second using std::move, and print the value through second followed by whether each pointer is now null.

For the input 9 the program prints exactly the output shown in Expected Output.

The last two lines print the result of a comparison (1 for true, 0 for false), never a pointer itself. Do not write delete and do not use a raw new.

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
Topics:
Pointers
📥 Auto-Input:
9\n
This input is automatically fed to your program's stdin
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.