[A89] Re: Pointers and Matricies
[Prev][Next][Index][Thread]
[A89] Re: Pointers and Matricies
I would write:
char matrix1[5][5]={{0,0,0,0,0}{0,0,0,0,0}{0,0,0,0,0}{0,0,0,0,0}{0,0,0,0,0}};
char **pmatrix1 = matrix1;
and then access the stuff with like
pmatrix[1][1] = 1;
Since the array is twodimensional you need two *, one for each [].
it is a pointer to a pointer.
putting a [] behind a pointer or array (wich is really the same thing,
except you cant change the address of an array)
like this pointer[5] is the same thing as writeing *(pointer+5)
///Olle
At 21:49 2001-02-22, you wrote:
>If I have a matrix such as thus:
>
>char matrix1[5][5]=
>{{0,0,0,0,0}{0,0,0,0,0}{0,0,0,0,0}{0,0,0,0,0}{0,0,0,0,0}};
>
>and I also have a pointer, thus:
>
>char * pmatrix1 = &matrix1;
>
>How would I go about referencing a single element in the matrix using ONLY
>the pointer?
>I tried doing this:
>
>pmatrix[1][1]=1;
>
>But that doesn't work. Can someone help me out? Much appreciation!
>
>CalenWakefield
Follow-Ups:
References: