Last active
October 9, 2022 01:12
-
-
Save mu8086/03e6b28ff9703c0b24f3a2e721bbb6d2 to your computer and use it in GitHub Desktop.
[C] Allocate 2D Array
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 ** 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