Question: > 
> **Possible Duplicate:**  
> 
> [Multi-dimensional array in C++](https://stackoverflow.com/questions/8902055/multi-dimensional-array-in-c) 
> 
> 
> 

I need to create a function that has one parameter which is a multi-dimensional array with two dimensions being user-specified, e.g.

```
    int function(int a, int b, int array[a][b])
    {
     ...

    }

```

How would I do that in C++ ?

Answer: 
You can do something like this with a template:

```
template <int A, int B>
int function(int array[A][B])
{
 ...
}

```

Note that this generates a block of code for each size of array that you use. You can optimise slightly by passing in the outer dimension as a function parameter instead of a template parameter (you can't change the inner dimension because you can't have an array of an array of unknown size).

EDIT: As pointed out on the duplicate bug, I got my template array syntax wrong.
You have to pass size with parameters.  

`int function(int a, int b, int array[][])`  

There is no length() method or a method like that in C++. If you pass an array, it's just a link to that. This is the same as `int function(int a, int b, int** array)`  

**EDIT:**  

Note that if you use square braces, not asterisks, you have to give size of all dimensions except the first one. Actually you're passing array of arrays and compiler must know size of each of them.