Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nixpulvis/d5cbc6fdb06ecf20c6ff to your computer and use it in GitHub Desktop.
Save nixpulvis/d5cbc6fdb06ecf20c6ff to your computer and use it in GitHub Desktop.
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