Skip to content

Instantly share code, notes, and snippets.

@lesovsky
Created July 13, 2015 14:49
Show Gist options
  • Save lesovsky/73caa7d52071c20cf232 to your computer and use it in GitHub Desktop.
Save lesovsky/73caa7d52071c20cf232 to your computer and use it in GitHub Desktop.
Create 3d array pointer and allocate space
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n_rows = 10, n_cols = 20, tup_size=64;
char ***z;
z = malloc(n_rows * sizeof(char **));
assert(z != NULL);
for (i = 0; i < n_rows; ++i)
{
z[i] = malloc(n_cols * sizeof(char *));
assert(z[i] != NULL);
for (j = 0; j < n_cols; ++j)
{
z[i][j] = malloc(tup_size);
assert(z[i][j] != NULL);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment