The typical 1-D array can be statically or automatically allocated in a declaration.
enum { n=100 };
int arr1[n];
Or dynamically-allocated
If you define a
as a pointer to an array of n
integers, the compiler will do the index arithmetic.
#define N 7
int (*a)[N];
int main() {
a = malloc(N*N*sizeof(int));
a[2][3] = 0;
}
ADDED:
Similarly, a three dimensional example:
#include
#include
#define N 7
int (*a)[N][N];
int main() {
int i,j,k;
a = malloc(N*N*N*sizeof(int));
for(i=0; i