title: Passing a char pointer array to a function
body: <p>I have written following sample code to demonstrate my problem</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string.h&gt;
  
  using namespace std;
  
  void f (char*** a)
  {
      *a = new (char*[2]);
      *a[0] = new char[10];
      *a[1] = new char[10];
      strcpy(*a[0], "abcd");
      strcpy(*a[1],"efgh");
  }
  
  int main ()
  {
      char** b = NULL;
      f(&amp;b);
      cout&lt;&lt;b[0]&lt;&lt;"\n";
      cout&lt;&lt;b[1]&lt;&lt;"\n";
      return 1;
  }
  </code></pre>
  
  <p>In this code i found that <em>a = new (char</em>[2]); not allocating memory of *a[1]. </p>
  
  <p>In gdb i am getting following seg fault.  </p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  0x0000000000400926 in f (a=0x7fffffffdfe8) at array1.cpp:10
  10          *a[1] = new char[10];
  (gdb) p *a[1]
  Cannot access memory at address 0x0
  </code></pre>
  
  <p>This is really confusing me. Can someone explain where i am going wrong.</p>
  
  <p>I know i can pass argument like void f (char**&amp; a) and by calling function f(b) and this works . But i want to know want happening if i use char*** a. It should also work. Sorry if this is an stupid question.<br>
  Any tutorial or reference on above problem will be appreciated.<br>
  Thanks in advance. </p>