You need to declare your matrix as a pointer to an integer pointer. Here is an example:
#include <stdio.h>
#include <stdlib.h>
#define NEW_ARRAY(ptr, n) \
{ \
(ptr) = malloc((n) * sizeof (ptr)[0]); \
if ((ptr) == NULL) { \
fprintf(stderr, "error: Memory exhausted\n"); \
exit(EXIT_FAILURE); \
} \
}
int main(void)
{
const int m = 2, n = 2;
int **A;
int i, j;
/*allocate matrix*/
NEW_ARRAY(A, m);
for (i = 0; i < m; i++) {
NEW_ARRAY(A[i], n);
}
/*initialize matrix*/
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
A[i][j] = i + j;
}
}
/*print matrix*/
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
printf("%d ", A[i][j]);
}
putchar('\n');
}
return 0;
}