pointer to preallocated memory as an input parameter and have the function fill it
<p>Test code:</p>

<pre><code>void modify_it(char * mystuff)
{
   //last element is null i presume for c style strings here.
   char test[7] = "123456";

   //when i do this i thought i should be able to gain access to this
   //bit of memory when the function is destroyed but that does not
   //seem to be the case.
   //static char test[] = "123123";

   //this is also creating memory on stack and not the heap i reckon
   //and gets destroyed once the function is done with.
   //char * test = new char[7];

   //this does the job as long as memory for mystuff has been
   //allocated outside the function.
   strcpy_s(mystuff,7,test); 

   //this does not work. I know with c style strings you can't just do
   //string assignments they have to be actually copied. in this case
   //I was using this in conjunction with static char test thinking
   //by having it as static the memory would not get destroyed and i can
   //then simply point mystuff to test and be done with it. i would later
   //have address the memory cleanup in the main function.
   //but anyway this never worked.
   mystuff = test;
}

int main(void)
{
  //allocate memory on heap where the pointer will point 
  char * mystuff = new char [7];
  modify_it(mystuff);
  std::string test_case(mystuff);

  //this is the only way i know how to use cout by making it into a c++ string.
  std::cout&lt;&lt;test_case.c_str();

  delete [] mystuff;
  return 0;
}
</code></pre>

<ol>
<li>In the case of a static array in the function why would it not work? </li>
<li>In the case when I allocated memory using new in the function does it get created on the stack or heap?</li>
<li>In the case when I have a string which needs to be copied into a <code>char *</code> form. everything I see usually requires <code>const char*</code> instead of just <code>char*</code>. </li>
</ol>

<p>I know I could use a reference to take care of this easily. Or <code>char **</code> to send in the pointer and do it that way. But I just wanted to know if I could do it with just <code>char *</code>. Anyway your thoughts and comments plus any examples would be very helpful. </p>
