Skip to content

Instantly share code, notes, and snippets.

@9thbit
Created November 9, 2011 13:47
Show Gist options
  • Save 9thbit/1351468 to your computer and use it in GitHub Desktop.
Save 9thbit/1351468 to your computer and use it in GitHub Desktop.
Dynamically allocate a 2D matrix of ints
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