On Thu, 10 Apr 2008 23:25:52 -0700 (PDT), cplusplusquestion@[EMAIL PROTECTED]
>There is a two-dimensional array:
>
>int grades[MAX][MAX];
>for( i = 0; i < MAX; i++)
> for( j = 0; j < MAX; j++)
> grades[i][j] = -1;
>
>I would like to assign an another variable to this array, for example:
>
>int another_grades[MAX][MAX];
>for( i = 0; i < MAX; i++)
> for( j = 0; j < MAX; j++)
> another_grades[i][j] = grades[i][j];
>
>Here, I need to declare another array. Is it possible to have a
>pointer to point grades[MAX][MAX]? As I've tried:
>
>int** another_g = grades;
The expression grades has an array type. Since this is not one of the
exceptions, the expression is automatically converted to the address
of the first element of the array with type pointer to element type.
In other words, the expression grades is treated exactly the same as
&grades[0]. Since grades[0] is itself an array of MAX int, what you
need is
int (*another_g)[MAX] = grades;
Since it is a bit unusual to want to deal with the array as a whole,
you might be better served with
int *another_g = &grades[0][0];
which resolves to the same address but with a more usable type.
>
>it does not work. Any good idea?
Remove del for email


|