← const Correctness with Pointers

Fix: Wrong const

hard

This is the “Double In Place” pattern from the previous lesson – except this version doesn’t compile. Submit it as-is and read the error before changing anything.

The bug isn’t in the arithmetic; it’s a const that shouldn’t be there. double_value’s entire purpose is to write a new value through its pointer parameter – that’s fundamentally at odds with declaring that parameter const int *, which promises the opposite. Unlike the earlier exercises in this lesson, where const was exactly right, here it’s a real bug: not every pointer parameter should be const, only the ones that genuinely never write through it. Part of const-correctness is knowing when not to reach for const, not just how to write it.

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