1. ## pointer to matrix

Say I have a matrix (that is of dimension DIM) of shorts called m1 and I want to split it into 4 (2 by 2)'s:

I need a pointer that will point to the short in

m1[dim/2]

I have tried the following:

short **B=&(m1[dim/2]);

// B is supposed to point to the short in m1[dim/2].
// m1 was passed into the function through its address as a
// short ***

I tried to check if B is pointing in the correct spot by doing this:

printf("%d ",B);

This however prints out an incorrect value. Any suggestions? 2. This is how i would do it..

Code:
```main(void){

short numbers[MAX_ROWS]={0};

/* pointer to a 2d array.  You must express how many dims there are */
short (*pNumbers)[MAX_ROWS] = NULL;

/* asign numbers to pointer to array */
pNumbers= numbers;

/* using the pointer */
pNumbers = 9998;

/* using none pointer */
numbers = 7777;

/* both work fine, and you can view access values using both*/
printf("\n%i", pNumbers);
printf("\n%i", numbers);```
Cheers,
G'n'R 3. short *p = &m1[dim/2];
without trying it, i don't see why this shouldn't work. check it and see

-Prelude 4. PRELUDE:

What you have: short *p = &m1[dim/2];
does work for me, but the thing is that I need p to be a short **.

And since m1 is a short *** type, when I do
short **p = &m1[dim/2];
I get an incorrect value.

Thanks. 5. I'm a bit confused, if using a single dereference works then why do you need to use a pointer to a pointer? 6. Because the statement is in a recursive function which has short** as an argument. 7. Dont know if i am understanding this correctly but if you want a pointer to a pointer i think this is the correct way. However some of it is unclear to me too. Anyway else??

Code:
```short **pp =NULL;
short *p = &m1[dim/2];

pp=&p;

/* this is where i am unclear.  Why not the need to dereference the pointer??? But it works */

pp= 8;

printf("%i\n", pp);

getch();```
Cheers
G'n'R Popular pages Recent additions 