title: Allocate memory 2d array in function C
body: <p>How to allocate dynamic memory for 2d array in function ?
  I tried this way:</p>
  
  <pre><code>int main()
  {
    int m=4,n=3;
    int** arr;
    allocate_mem(&amp;arr,n,m);
  }
  
  
  void allocate_mem(int*** arr,int n, int m)
  {
    *arr=(int**)malloc(n*sizeof(int*));
    for(int i=0;i&lt;n;i++)
      *arr[i]=(int*)malloc(m*sizeof(int));
  } 
  </code></pre>
  
  <p>But it doesn't work.</p>