>You can CERTAINLY create a 2D, 3D or 4D array:
Its only in your mind that that array can exist in more than one dimension, the compiler translates any higher dimensions into a single dimensions placed side by side but it cant always do the job. In order to create a true multidimensional array you need ptrs. The key difference is:
int foo[2][2][2][2];
foo[0][0][0][0] = 2;
foo[0][1][0][0] = 3;
int ****bar = foo; //wrong
printf("%d", bar[0][0][0][0]); //this segfaults
int *headptr = foo;
printf("%d", headptr[4]); //this works, why? the index is clearly out of bounds....because its a 1d array! This is the equivaluent of what you would think of as foo[0][1][0][0]. The following is a true multidimensional array.
int **twodimen = malloc(2*sizeof(int*));
twodimen[0] = malloc(2*sizeof(int));
twodimen[1] = malloc(2*sizeof(int));
twodimen[1][1] = 5;
int **test = twodimen;
printf("%d", test[1][1]); //This works!!
> This is usually discovered when dealing with multidimensional arrays.
As i said earlier, theres no such thing. Its simply a compiler hack (i.e. int foo[2][2] is implemented as int foo[4] and foo[1][1] gets translated to foo[3]...see above)
>Because that's one of the situations in which an array name decays to a pointer.
Thats semantics. It is for all intensive purposes a pointer.
>sizeof() is not a preprocessor directive. It is compiler proper - that's why you can't do something like
What I meant was that sizeof behaves like a preprocessor directive in that it isnt a real function. The compiler evaluates the size and then replaces the function call with the real number (i.e. malloc(sizeof(int)) gets translated to whatever target equivalent of the mips: $a0 = 4; jal malloc (for non assembly people: malloc(4)). Hence the uselesness of a function which evaluates the size of its argument (it'll always be the same).