quote:Original post by Anonymous Poster
*b == A[0][0] *b+1 == A[0][1] *b+2 == A[1][0] *b+3 == A[2][2]
Also, AP''s WOULD be a good representation of how to access the array through pointer notation except he screwed up his operator precidence. The CORRECT way of doing pointer notation would have been
*(b)
*(b+1)
*(b+2)
*(b+3)
He left out the parenthesis, so rather than accessing the different elements you would have just been adding values to the first element and actually wouldn''t have been doing pointer arithmentic at all.
Another way you could look at accessing the array is, using that same logic, the pattern
int a[numrows][numcols]
a[row][column] = &a[0][0] + row * numcols + column
this can be better understood by looking at the matrix a as an array of numrows arrays of length numcols, so every numcols worth of elements is the beginning of the next dimension. row * numcols gives you the 0th element of that row and adding column gives you the colum of that array.
Only use that method if you don''t know the dimensions of the array at runtime (IE if you dynamically allocate the array), or if you are passing the array to a function in which the lengths of the dimensions can vary.
Again, the original method I mentioned is probably the best way
int (*b)[2][2]
and it''s also the most readable when accessing elements -- ESPECIALLY when dealing with arrays of more than 2 dimensions (in which manually calculating the address becomes very drawn out and unreadable).