Pointers to 2D arrays 
Author Message
 Pointers to 2D arrays

Okay, I have a 2D array of floats, e.g.

  static const float coordinates[][ 3 ] =
  {
     { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 },
  };

What I want to do is hold a pointer to this variable (for example,
something like float* pF = coordinates) but I cannot for the life of me
think how to do this.   Probably extremely trivial solution and I'll kick
myself, but could someone please shed light on the problem.  
Thanks.

O.



Tue, 15 Feb 2000 03:00:00 GMT  
 Pointers to 2D arrays


Quote:

>Okay, I have a 2D array of floats, e.g.

>  static const float coordinates[][ 3 ] =
>  {
>     { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 },
>  };

>What I want to do is hold a pointer to this variable (for example,
>something like float* pF = coordinates) but I cannot for the life of me
>think how to do this.   Probably extremely trivial solution and I'll kick
>myself, but could someone please shed light on the problem.  
>Thanks.

When in doubt, use typedef:

    typedef float coord_t[3];

    coord_t coordinates[] = { { 1.0, 2.0, 3.0 }, /*..etc...*/ }

    coord_t *pF = coordinates;

When not in doubt, whip out the declaration syntax expertise:

    float (*pF)[3] = coordinates;



Tue, 15 Feb 2000 03:00:00 GMT  
 Pointers to 2D arrays

You might try pF = &(coordinates[0][0]);  or   pF = (int *)&(coordinates);



Quote:
> Okay, I have a 2D array of floats, e.g.

>   static const float coordinates[][ 3 ] =
>   {
>      { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 },
>   };

> What I want to do is hold a pointer to this variable (for example,
> something like float* pF = coordinates) but I cannot for the life of me
> think how to do this.   Probably extremely trivial solution and I'll kick
> myself, but could someone please shed light on the problem.  
> Thanks.

> O.



Tue, 22 Feb 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. 2D array of pointers to 2D arrays

2. Help : Pointer to 2D Array

3. Pointer to 2D array...

4. pointers and 2D array

5. Which 2D array of 2D array addressing method?

6. char pointer to 2D char array

7. converting 2D array to pointer

8. a dynamical 2D array to a double pointer

9. HOWTO:2d array of pointers to structure

10. pointer arithmetic with 2d arrays?

11. Pointer of a 2d array

12. Help needed: 2D arrays and pointers in ANSI C.

 

 
Powered by phpBB® Forum Software