-
Accessing array members
Hello,
are all the ways to access a member of a two-dimensional array listed below correct? I've tested the code and it seems to work properly.
Code:
void do_something(int (*ap)[COLUMNS], int rows, int columns)
{
int x, i, j;
... // assume we've assigned some values to i and j here
x = (*(ap+i))[j]);
x = *(&ap[0][0] + i * columns +j));
x = *(*(ap+i) + j));
x = ap[i][j];
}
-
You need COLUMNS and columns to represent the same number, for sure. But if that's true, then those should all get you to the same place, should you ever use any of them, which is between you and your conscience.