Skip to content

Instantly share code, notes, and snippets.

@mu8086
Last active October 9, 2022 01:12
Show Gist options
  • Save mu8086/03e6b28ff9703c0b24f3a2e721bbb6d2 to your computer and use it in GitHub Desktop.
Save mu8086/03e6b28ff9703c0b24f3a2e721bbb6d2 to your computer and use it in GitHub Desktop.
[C] Allocate 2D Array
int ** int2dArray(int row, int col) {
int i, **ret = (int **) malloc(sizeof(int *) * row + sizeof(int) * row * col);
for (i = 1, ret[0] = (int *)(ret + row); i < row; ++i) {
ret[i] = ret[i-1] + col;
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment