I am not entirely clear on how to do pointers to multidimensional arrays. It seems that if p is a pointer to the first element of the multidimensional array then you cannot properly use the "p[i][j]" notation (my compiler returns an error, something along the lines of "subscripted value is neither an array nor a pointer"). Instead, you have to do a pointer to the first element of the array viewed as a 1-dim array of 1-dim arrays, which makes the typedefs somewhat more complicated. Furthermore, if you have a function which only knows the pointer to the first real element, you cannot use this trick and you have to do some arithmetic to work out the value. I am sure there must be a better way to do this.
This prints the correct answer of 4, but:Code:
typedef int Test;
int *TestFn(int *t)
t = 4;
int main ()
p = &k;
t = &k;
t = TestFn(t);
1. The line "t = 4" is rather cryptic. Obviously we know it is right because 1*8 + 3*1 = 11, but someone else might not know. Is there a way to put a double subscript to show the actual array position? As I commented earlier, "t" doesn't seem to work.
2. It is not entirely clear that k is a two-dim array. Obviously I would like to have a definition like:
but I then could not see what type to set p as. Is there a better way around this one too?Code: