title: C++ code to create dynamic array using new works in main, but doesn't work as a separate function
body: <p>I am relatively new to C++ programming (about half a year of C programming learning and 2 months of C++), so my question might seem (or be) stupid, but I've been searching the internet for awhile and also trying to figure out whats going on.</p>
  
  <p>I wrote a code that makes 2d (and later another to 3d) dynamic array which is working fine, but when I put it in to separate function there is a problem when I try to put the data (using cin) to this array.</p>
  
  <p>My code to make 2d array:</p>
  
  <pre><code>double tab** = new double*[x];
  for(int i=0; i&lt;x; i++){
      tab[i] = new double[y];
  }
  </code></pre>
  
  <p>And then to put the data into the array:</p>
  
  <pre><code>double tmc;
  for(int i=0; i&lt;x; i++){
      for(int j=0; j&lt;y; j++){
          cout&lt;&lt;"Type the value of : "&lt;&lt;i+1&lt;&lt;", "&lt;&lt;j+1&lt;&lt;endl;
          my_fun_input(&amp;tmc);
          tab2d[i][j]=tmc;
      }
  }
  </code></pre>
  
  <p>my_fun_input is my function that looks like:</p>
  
  <pre><code>void my_fun_input(double* number){
  cin&gt;&gt;*number;
  while(cin.good()==false){
      cout&lt;&lt;"Error! Bad value."&lt;&lt;endl;
      cin.clear();
      cin.ignore();
      cin&gt;&gt;*number;
  }}
  </code></pre>
  
  <p>And the problem is that when I use it directly it' s working, but when I move the first piece of code that is creating the 2d array to separate function like this:</p>
  
  <pre><code>void table(double** tab, int x, int y){
  tab = new double*[x];
  for(int i=0; i&lt;x; i++){
      tab[i] = new double[y];
  }}
  </code></pre>
  
  <p>I am using this function like this:</p>
  
  <pre><code> double** tab2d=NULL;
   int x, y; //size obtained from user
   table(tab2d, x, y);
  </code></pre>
  
  <p>After using this function the code to put data into works for first element and then the program is crushing.
  What can cause this?
  Thanks for help in advance.</p>
  
  <p>PS. Sorry for my poor english.</p>