A
Anthony Moss
How do you use a double pointer to access a two dimensional array.
ie int a[3][3];
int **p;
-
-
-
-
-
etc.
thanks
Anthony
ie int a[3][3];
int **p;
-
-
-
-
-
etc.
thanks
Anthony
Anthony said:How do you use a double pointer to access a two dimensional array.
ie int a[3][3];
int **p;
Anthony said:How do you use a double pointer to access a two dimensional array.
ie int a[3][3];
int **p;
Anthony Moss said:How do you use a double pointer to access a two dimensional array.
ie int a[3][3];
int **p;
In said:How do you use a double pointer to access a two dimensional array.
ie int a[3][3];
int **p;
ie int a[3][3];
int **p;
Dan said:How do you use a double pointer to access a two dimensional array.
ie int a[3][3];
int **p;
You don't. You may want to read the FAQ, BTW.
Dan
Guillaume said:While with:
int a[m][n]
a[j] is the same as: *(a + n*i + j)
with:
int * a[n]
a[j] is the same as: *(*(a + i) + j)
Guillaume said:While with: int a[m][n]
a[j] is the same as: *(a + n*i + j)
with: int * a[n]
a[j] is the same as: *(*(a + i) + j)
That is a rather nice summary!
a[j] is the same as: *(a + n*i + j)
with: int * a[n]
a[j] is the same as: *(*(a + i) + j)
That is a rather nice summary!
Yes, except for one technical flaw -- the first expression is not
legal C
Guillaume said:While with: int a[m][n]
a[j] is the same as: *(a + n*i + j)
with: int * a[n]
a[j] is the same as: *(*(a + i) + j)
That is a rather nice summary!
Yes, except for one technical flaw -- the first expression is not
legal C
How is it not legal, please?
Joona I Palaste said:Guillaume said:While with: int a[m][n]
a[j] is the same as: *(a + n*i + j)
with: int * a[n]
a[j] is the same as: *(*(a + i) + j)
That is a rather nice summary!
Yes, except for one technical flaw -- the first expression is not
legal C
How is it not legal, please?
Well, the expressions aren't equivalent. a[j] has type "int" but
*(a + n*i + j) has type "int (*)[n]". It's legal C, all right - but
if the value of i is too high, you end up reading unallocated memory,
because *(a + n*i + j) is the same as a[n*i + j].
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.