Pointer of a 2d array 
Author Message
 Pointer of a 2d array

Hello!

How do I return a pointer of a 2d array?
I have this array:

char hello[5][5];

and I want to return a pointer to it:

char (????)GetHello() { return (????)hello; }

what should be there instead of the ?s?

Thank you

Fredrik Hellman



Thu, 17 Jul 2003 01:11:49 GMT  
 Pointer of a 2d array

Quote:

> How do I return a pointer of a 2d array?

Nit: `pointer to', not `pointer of'.

Quote:
> I have this array:

> char hello[5][5];

> and I want to return a pointer to it:

> char (????)GetHello() { return (????)hello; }

> what should be there instead of the ?s?

Use cdecl (see the FAQ):

    blp:~(0)$ cdecl
    Type `help' or `?' for help
    cdecl> declare GetHello as function returning pointer to array 5 of array 5 of char;
    char (*GetHello())[5][5]
    cdecl>

There you go.



Thu, 17 Jul 2003 01:14:37 GMT  
 Pointer of a 2d array

Quote:

>How do I return a pointer of a 2d array?
>I have this array:

>char hello[5][5];

>and I want to return a pointer to it:

>char (????)GetHello() { return (????)hello; }

>what should be there instead of the ?s?

  char (*GetHello(void))[5][5] { return &hello; }

-- Mat.



Thu, 17 Jul 2003 01:26:06 GMT  
 Pointer of a 2d array
On Sat, 27 Jan 2001 17:11:49 GMT, "Fredrik Hellman"

Quote:

>Hello!

>How do I return a pointer of a 2d array?
>I have this array:

>char hello[5][5];

>and I want to return a pointer to it:

>char (????)GetHello() { return (????)hello; }

>what should be there instead of the ?s?

>Thank you

>Fredrik Hellman


Not to disagree with the previous correct responses, my preference is
for something that will be readable later:

        typedef char five_by_five[5][5];
        five_by_five hello;

        five_by_five* GetHello(void)
                {return &hello;}

<<Remove the del for email>>



Thu, 17 Jul 2003 04:15:47 GMT  
 Pointer of a 2d array
Thanks all of you!
(Pointer TO :-)

Fredrik Hellman



Fri, 18 Jul 2003 04:40:28 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. pointer arithmetic with 2d arrays?

2. Question: How to declare a pointer to a 2d array

3. 2D array of pointers to 2D arrays

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

5. Help : Pointer to 2D Array

6. char pointer to 2D char array

7. Pointers to 2D arrays

8. converting 2D array to pointer

9. a dynamical 2D array to a double pointer

10. Pointer to 2D array...

11. HOWTO:2d array of pointers to structure

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

 

 
Powered by phpBB® Forum Software