← Back to Pointers
Question 707
Watch use_count as Owners Join and Leave
Watch use_count as Owners Join and Leave
Read one integer from standard input and follow these steps in order, printing a line after each: 1. Createa, ashared_ptr<int>built withmake_shared, owning that number. Printa.use_count(). 2. Makeba copy ofa. Print the count. 3. Makeca copy ofa. Print the count. 4. Callc.reset()socgives up ownership. Print the count. 5. Add 5 to the number through `b`, then print it through `a`. For the input12the program prints exactly the output shown in Expected Output. Do not writedeleteand do not use a rawnew.
Expected Output:
after a: 1 after b: 2 after c: 3 after reset: 2 value: 17
= 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.