Created
November 9, 2011 13:47
-
-
Save 9thbit/1351468 to your computer and use it in GitHub Desktop.
Dynamically allocate a 2D matrix of ints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int **int_matrix_alloc(int n, int m){ | |
int *a, **aa, i; | |
a = (int *)calloc(n * m, sizeof(int)); | |
aa = (int **)calloc(n, sizeof(int *)); | |
for(i=0;i<n;i++){ | |
aa[i] = &a[i * m]; | |
} | |
return aa; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment