C++ cout pointer
<p>Hello
Can somebody explain why second <strong>cout</strong> in func(char *p) doesn't work:</p>

<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;

using namespace std;

char *strhex(char *str);
char *func(char *p);

int  main()
{
     char *ptr;    

     char *p=strhex("d");
     cout&lt;&lt;"main:"&lt;&lt;p&lt;&lt;endl;

     cout&lt;&lt;func(p)&lt;&lt;endl;

     system("PAUSE");
     return 0;
}

char *func(char *p)
{ 
      cout&lt;&lt;"func1:"&lt;&lt;p&lt;&lt;endl;
      char buffer[500]="";
   char *zbuffer = buffer; 
      cout&lt;&lt;"func2:"&lt;&lt;p&lt;&lt;endl; ///doesn't work

      return zbuffer;
}

char *strhex(char *str)
{
     char buffer[500]="";
  char *pbuffer = buffer;
  int len = strlen( str );

     for( int i = 0; i &lt; len ;i++ )
  {
  itoa(str[i],pbuffer,16);  
        pbuffer +=2;
     };

     *pbuffer = '\0'; 
     pbuffer=buffer;

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

<p>Edit:
i'm using DEV C++ 4.9.9.2 on Windows</p>
