Copy constructors in C++ and copying values into objects
<pre><code>#include &lt;iostream&gt;
#include &lt;cstring&gt;
using namespace std;

class foo {
     int number;
     char string[20];
public:
     foo( ) { 
          set(3, 5); 
     }
     void set (int a, int b) { 
          number = a + b;
        strcpy( string, "summer" ); 
     }

     foo (const foo &amp; c ) { 
     }

     void output() { 
          cout &lt;&lt; number &lt;&lt; ',' &lt;&lt; string &lt;&lt; endl;  
     }
};

void showyanothing (foo);

int main() {
     foo a, b;
     showyanothing( a );
     a.output();
     b.output();
}

void showyanothing (foo z) { 
     cout &lt;&lt; "... how are you?\n";
     z.output(); 
}
</code></pre>

<p>Output</p>

<pre><code>... hello ...
... how are you?
-1218897013,l·ôl·Y·ôl·À
8,summer
8,summer
</code></pre>

<p>The line with <code>-1218897013,l·ôl·Y·ôl·À</code>, those are the values in the object Z created by the copy constructor. If I change my copy constructor to the following, outputting object z will yield <code>10, summer.1.2.3</code>. Why? Where did the values magically get inserted from into Z?</p>

<p>new copy constructor</p>

<pre><code> foo (const foo &amp; c ) { 
     number = c.number + 2;
     strcpy( string, c.string );
     strcat( string, ".1.2.3" );
 }
</code></pre>

<p>new output:</p>

<pre><code>... how are you?
10,summer.1.2.3
8,summer
8,summer
</code></pre>

<p>In the copy constructor, what I'm confused about is why does c.number equate to 8, and c.string equate to summer? Where did it get those values from?</p>
