Return ++a is different than return a++, why? : <p>I was experimenting with some code when I discovered something odd. I had the following code:</p>

<pre><code>#include &lt;iostream&gt;

int add_one_return(int a) {
    return a++;
}
void add_one_ref(int &amp;a) {
    a++;
}

int main(int argc, char const *argv[]) {
    int a1 = 5;
    int a2 = 5;
    a1 = add_one_return(a1);
    add_one_ref(a2);
    std::cout &lt;&lt; a1 &lt;&lt; " " &lt;&lt; a2 &lt;&lt; std::endl;
    return 0;
}
</code></pre>

<p>But when I ran it the program printed <code>5 6</code>. I went back and changed <code>add_one_return</code> to:</p>

<pre><code>int add_one_return(int a) {
    return ++a;
}
</code></pre>

<p>and it worked! Why does <code>++a</code> work but not <code>a++</code>? Is there ever an advantage to <code>a++</code>, because I also hear that in a for loop you want to use <code>for(int i = 0; i &lt; someVar; ++i) {}</code>, so why <code>a++</code> at all?</p>
