C++ Static Array Initialization - Memory Issue
<p>I have a header file which contains a member variable declaration of a static char array:</p>

<pre><code>class ABC 
{ 
public:
static char newArray[4];
// other variables / functions
private:
void setArray(int i, char * ptr);
}
</code></pre>

<p>In the CPP file, I have the array initialized to NULL:</p>

<pre><code>char ABC::newArray[4] = {0};
</code></pre>

<p>In the ABC constructor, I need to overwrite this value with a value constructed at runtime, such as the encoding of an integer:</p>

<pre><code>ABC::ABC()
{ 
int i; //some int value defined at runtime
memset(newArray, 0, 4); // not sure if this is necessary
setArray(i,newArray);
} 

...

void setArray(int i, char * value)
{
    // encoding i to set value[0] ... value [3]
}
</code></pre>

<p>When I return from this function, and print the modified newArray value, it prints out many more characters than the 4 specified in the array declaration.</p>

<p>Any ideas why this is the case.
I just want to set the char array to 4 characters and nothing further.</p>

<p>Thanks...</p>
