title: Assigning a value to a pointer to a const pointer to a const char (const char * const * p)
body: <p>I am new to C++ and am struggling to make the following code work:</p>
  
  <pre><code>struct Keywords
  {
       const char* const* keys;
       int count;
  }
  
  Keywords GetKeywords()
  {
       Keywords keywords;
       keywords.count = 10;
       string keys = "a b c d e";
       keywords.keys = keys???;
       return keywords;
  }
  
  int main(int argc, char *argv[])
  {
       Keywords keywords = GetKeywords();
       cout&lt;&lt;keywords.count&lt;&lt;endl; //prints 10
       cout&lt;&lt;keywords.keys&lt;&lt;endl;  //prints a memory address like 0030F838
  }
  </code></pre>
  
  <p>How can I make <code>keys</code> to point to <code>a b c d e</code>?
  So far I have tried this</p>
  
  <pre><code>char * writable = new char[keys.size() + 1];
  strcpy(writable, keys.c_str());
  writable[keys.size()] = '\0';
  
  const char* a = writable;
  const char** ptr = &amp;a;
  results.keys = ptr;
  </code></pre>
  
  <p>While debugging I can see that <code>results.keys</code> shows <code>a b c d e</code>, but as soon as <code>GetKeywords()</code> is returned, <code>results.keys</code> points to unreadable memory location.</p>
  
  <p>I cannot make any changes to <code>struct Keywords</code> and <code>GetKeywords()</code> method signature.</p>