← Back to Pointers
Question 708
Owner Count Falls Back After the Block Ends
Owner Count Falls Back After the Block Ends
Read one integer from standard input and write a program that: 1. Createsowner, ashared_ptr<int>built withmake_sharedholding that number, and prints the owner count. 2. Opens a plain inner block{ }and, inside it, makes two moreshared_ptr<int>copies ofowner, prints the owner count from inside the block, and doubles the number through one of the copies. 3. After the block has closed, prints the owner count again and then the number. For the input8the program prints exactly the output shown in Expected Output. Do not writedeleteand do not use a rawnew.
Expected Output:
before block: 1 inside block: 3 after block: 1 value: 16
= 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.