title: C-2d array print function not working when I call it in main function
body: <p>I wrote two functions, readMatrix which allocate a double pointer and take the input from keyboard and the second function is a print function.</p>
  <p>When I call the print function in main function, it does not work completely.</p>
  <p>This is the code :</p>
  <pre><code>void print(int** mat, int lin, int col) {
      int i,j;
      printf(&quot;Matrix is:\n&quot;);
      for(i=0; i&lt;lin; i++) {
          for(j=0; j&lt;col; j++) {
              printf(&quot;%d &quot;, *(*(mat+i)+j));
          }
          printf(&quot;\n&quot;);
      }
  }
  
  int** readMatrix(int** mat, int lin, int col) {
      int x;
      int i,j;
      mat==(int**)malloc(lin*sizeof(int*));
      for(x=0; x&lt;lin; x++) {
          mat[x]=(int*)malloc(col*sizeof(int));
      }
      
      for(i=0; i&lt;lin; i++) {
          printf(&quot;Line %d: &quot;, i);
          for(j=0; j&lt;col; j++) {
              scanf(&quot;%d&quot;,  &amp;mat[i][j]);
          }
      }
  }
  
  
  int main()
  {
      int lin, col;
      int i,j;
      printf(&quot;Enter number of lines: &quot;);
      scanf(&quot;%d&quot;, &amp;lin);
      printf(&quot;Enter number of cols: &quot;);
      scanf(&quot;%d&quot;, &amp;col);
      int** mat = readMatrix(mat,lin,col);
      print(mat,lin,col);
      return 0;
  }
  </code></pre>
  <p>After I take the input, I get the message &quot;Matrix is&quot; but the matrix does not appear, why?</p>
  <p>If I call the print function inside readMatrix function, it works, but why is not working if I call it in main?</p>
  <p>Thanks.</p>