Returning a pointer to 2-D array from a function.

I know how to pass a 2-D array to a function. The prototype for that is
void f(int (*p)[2]) assuming the array is of integers and there are 2 columns in it.

However, if I wanted the same function to return a pointer to a 2-D array, what would be the prototype?

Thanks in advance. If my question is a little ambiguous, please feel free to ask me to clarify further.
i dont know exact syntax, so you can create typedef:
typedef int(*type_t)[2];
type_t f(type_t p)
{
return p;
}

though overall, returning array with function seems silly and unsafe.
Here is an example code using a function that returns a pointer to a 2d array.
The function will allocate the 2x3 2d array and fill values as below:

1
2
1 2 3
2 4 6


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;

void func(int ***ptrToA2DArray) {
    // allocate and fill values to a 2d (2 x 3) array with

    //allocate first dimension
    *ptrToA2DArray = new int*[2];

    //Allocate second dimension and fill values
    for (int i = 0; i < 2; i++) {
        (*ptrToA2DArray)[i] = new int[3];
        //fill 3 int values
        for (int j = 0; j < 3; j++) {
            (*ptrToA2DArray)[i][j] = (j + 1) * (i + 1);
        }
    }
}

int main() {
    int **ptrToAnArray = NULL;

    //allocate and fill the 2 x 3 2d array
    func(&ptrToAnArray);

    //display 2d array
    cout << "Displaying 2x3 2d array..." << endl;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++) {
            cout << ptrToAnArray[i][j] << " ";
        }
        cout << endl;
    }

    //free 2d array
    for (int i = 0; i < 2; i++) {
        delete [] ptrToAnArray[i];
    }
    delete [] ptrToAnArray;

    return 0;
}
Topic archived. No new replies allowed.