← The Rule of Three (and Five) & RAII

Cleanup on Early Return

medium

Add an ordinary early return to process: if value is negative, print Invalid value and return before reaching the Processing: line. There’s nothing unusual about the if itself – the point of this exercise is what happens around it.

Look at the expected output for a negative input: Released: resource still prints, in both cases, in the same relative position (right before the function actually exits) – whether process falls all the way through to the bottom or exits early through your new return. That’s RAII’s actual guarantee made visible: g’s destructor is tied to g going out of scope, not to any particular line of code reaching the bottom of the function. You don’t write anything to make Released: resource appear in the early-return case – it already does, for free, the moment g’s scope ends.

Your solution

"Run" uses the sample stdin ("5"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution