How can I trust the behavior of C++ functions that declare const? <p>This is a C++ disaster, check out this code sample:</p> <pre><code>#include &lt;iostream&gt; void func(const int* shouldnotChange) { int* canChange = (int*) shouldnotChange; *canChange += 2; return; } int main() { int i = 5; func(&amp;i); std::cout &lt;&lt; i; return 0; } </code></pre> <p>The output was 7!</p> <p>So, how can we make sure of the behavior of C++ functions, if it was able to change a supposed-to-be-constant parameter!?</p> <p>EDIT: I am not asking how can I make sure that <strong>my</strong> code is working as expected, rather I am wondering how to believe that someone else's function (for instance some function in some dll library) isn't going to change a parameter or posses some behavior...</p>