how copy constructors work
<pre><code>#include &lt;iostream&gt;
#include &lt;cassert&gt; // for assert

class IntArray
{
private:
int m_length = 0;
int *m_array = nullptr;

public:
IntArray(int length):
    m_length(length)
{
    if (length &lt;= 0)
        assert("IntArray length should be a positive integer");

    m_array = new int[m_length] { 0 };
}

// Copy constructor that does a deep copy
IntArray(const IntArray &amp;array):
    m_length(array.m_length)
{
    // Allocate a new array
    m_array = new int[m_length];

    // Copy elements from original array to new array
    for (int count = 0; count &lt; array.m_length; ++count)
        m_array[count] = array.m_array[count];
}

~IntArray()
{
    delete[] m_array;
}

// If you're getting crazy values here you probably forgot to do a deep copy in your copy constructor
friend std::ostream&amp; operator&lt;&lt;(std::ostream &amp;out, const IntArray &amp;array)
{
    for (int count = 0; count &lt; array.m_length; ++count)
    {
        std::cout &lt;&lt; array.m_array[count] &lt;&lt; ' ';
    }
    return out;
}

int&amp; operator[] (const int index)
{
    assert(index &gt;= 0);
    assert(index &lt; m_length);
    return m_array[index];
}

// Assignment operator that does a deep copy
IntArray&amp; operator= (const IntArray &amp;array)
{
    // self-assignment guard
    if (this == &amp;array)
        return *this;

    // If this array already exists, delete it so we don't leak memory
    delete[] m_array;

    m_length = array.m_length;

    // Allocate a new array
    m_array = new int[m_length];

    // Copy elements from original array to new array
    for (int count = 0; count &lt; array.m_length; ++count)
        m_array[count] = array.m_array[count];

    return *this;
}

};

IntArray fillArray()
{
IntArray a(5);
a[0] = 5;
a[1] = 8;
a[2] = 2;
a[3] = 3;
a[4] = 6;

return a;
}

int main()
{
IntArray a = fillArray();

// If you're getting crazy values here you probably forgot to do a deep copy in your copy constructor
std::cout &lt;&lt; a &lt;&lt; '\n';

IntArray b(1);
a = a;
b = a;

 // If you're getting crazy values here you probably forgot to do a deep   copy in your assignment operator
// or you forgot your self-assignment check
std::cout &lt;&lt; b &lt;&lt; '\n';

return 0;
}
</code></pre>

<p>so im trying to understand this code. I know the copy constructor is going to be called for IntArray a = FillArray().  However I do not know how IntArray(const IntArray &amp;array) works. I understand the syntax, but dont understand where array.m_length is coming from. Nor am I understanding how these values get returned to IntArray a.  Please help.</p>