CJCoding With Joseph
15free / daySign inCreate account

Owner Count Falls Back After the Block Ends

Read one integer from standard input and write a program that:
1. Creates owner, a shared_ptr<int> built with make_shared holding that number, and prints the owner count.
2. Opens a plain inner block { } and, inside it, makes two more shared_ptr<int> copies of owner, 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 input 8 the program prints exactly the output shown in Expected Output.

Do not write delete and do not use a raw new.

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
Topics:
Pointers
📥 Auto-Input:
8\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.