Why I can use non const variable to receive const function
<p>The outcome of this piece of program I am testing doesn't make sense to me:</p>

<pre><code>class CC {
public:
    int a;
    CC();
    CC(int a);
    ~CC();
};

CC::CC() {
    this-&gt;a = 0;
}

CC::CC(int a) {
    this-&gt;a = a;
}

CC::~CC() {

}

const CC f() {
    CC cc(2);
    cout &lt;&lt; &amp;cc &lt;&lt; endl;
    return cc;
}

int main() {
    CC cc = f();
    cc.a = 3;
    cout &lt;&lt; &amp;cc &lt;&lt; " " &lt;&lt; cc.a &lt;&lt; endl;
}


result: // note the address are the same
0x7ffdd24b26e0
0x7ffdd24b26e0 3
</code></pre>

<p>What I don't understand is why I can use a non const variable inside main() to receive a const return value function? The memory address are the same so the two local variables should be pointing to the same object.</p>

<p>g++ version:</p>

<pre><code>g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
</code></pre>