Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Contiguous 2D Matrix C99
int main(int argc, char **argv) {
size_t rows = atoi(argv[1]);
size_t columns = atoi(argv[2]);
/* This is really cool!!! */
int (*matrix)[columns] = malloc(sizeof(*matrix) * rows);
if (matrix) {
matrix[0][0] = 13;
matrix[1][0] = 1;
for (size_t i = 0; i < rows; i++) {
for (size_t j = 0; j < columns; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
free(matrix);
}
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.