How to pass a 2D array by reference? Can somebody guide me?

if I created an array as follows:

char **sarray;
2Darray = new char* [row];
for(i=0; i<row; i++)
2Darray = new char[col];

(NOTE: I get the values of row and colume via some calculations in my code ....basically, I am gathering values from a text file into and placing it in a 2D array... so each text file may result in diff row & colume sizes)

I got the 2D array I need...now I want to pass it by reference to another function. How to do that?

> How to pass a 2D array by reference?
What's wrong with pointers? Just accept a char ** as the array, and then pass it the 2 array dimensions, so the function knows the boundaries.

I don't know how to pass the sizes of the rows & columns actually ....

can you provide me the syntax for passin by reference ? I don't know how to pass it the 2 array dimensions, so the function knows the boundaries.

help

>I don't know how to pass the sizes of the rows & columns actually ....
Pass them as integers.

>can you provide me the syntax for passin by reference ?
I'd say that's pretty pointless (no pun intended) to pass by reference, when you've created the array with pointers. So use pointers. Here's how I would do it with pointers:

void myFunction(char **array, int arrayWidth, int arrayHeight) {
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.