title: C. Segmentation Fault when function modifies dynamically allocated 2d array
body: <p>What i need is a function that modifies given pointer to 2d matrix like this: </p>
  
  <pre><code>void intMatrixAll(int row, int col, int **matrix);
  </code></pre>
  
  <p>Now, a function should allocate memory and the matrix could be used. Rows and cols are given at run-time. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #define PRINTINT(X) printf("%d\n", X);
  void intMatrixAll(int row, int col, int **matrix);
  
  int main(void) {
     int testArrRow = 4;
     int testArrCol = 6;
     int **testMatrix = NULL;
     intMatrixAll(testArrRow, testArrCol, testMatrix);
     testMatrix[2][2] = 112; //sementation fault here :(
     PRINTINT(testMatrix[2][2]);
     system("PAUSE");
     return 0;
  }
  
  void intMatrixAll(int row, int col, int **matrix) {
     printf("intMatrixAll\n");
     //allocate pointers:
     matrix = malloc(row * sizeof(int *));
     if(matrix == NULL) printf("Failed to allocate memmory.\n");
     for(int i=0; i&lt;row; i++) {
        //allocate space for cols: 
        matrix[i] = malloc(col * sizeof(int));
        if(matrix[i] == NULL) {
           printf("Failed to allocate memmory for arr[%d].\n", i);
           exit(0);
        }
     }
  }
  </code></pre>
  
  <p>Why am i getting error?</p>