c - incrementing array pointer
<p>Can someone explain to me why this doesn't work. I'm java developer and new to c/c++<br>
As far as i understood pointer of array is actually pointer of arrays first element, is that correct? </p>

<pre><code>void test(char *tmp)
{
    test2(tmp);
    //*tmp++ = '1';
    //*tmp++ = '2';
    *tmp++ = '3';
    *tmp++ = '4';
    *tmp = 0;
}

void test2(char *tmp)
{
    *tmp++ = '1';
    *tmp++ = '2';
}

int main(int argc, char **argv)
{
    char tmp[5];
    test(tmp);
    printf("%s", tmp);
    return 0;
}
</code></pre>

<p>only <code>34</code> gets printed. When i debug this code in function <code>test2</code> pointer of <code>tmp</code> is incremente by one but back in function <code>test</code> after test2 is called, pointer of <code>tmp</code> is back to its initial value.<br>
If i just put all of the code in single function like this, it works:  </p>

<pre><code>void test(char *tmp)
{
    *tmp++ = '1';
    *tmp++ = '2';
    *tmp++ = '3';
    *tmp++ = '4';
    *tmp = 0;
}
</code></pre>

<p>Also what does the <code>*tmp = 0</code> on the last line do. I copied it from some other code. Without it there is some junk on the end of the array.</p>