How to pass an array of string as pointers to a funtion?
filed in Xdela Community on May.26, 2010
For example i have one function void function(how to pass array of string as pointers?)
I have an array of program id for example i.e,P30234,P30324,P34253, and i want to pass these values to the function i mentioned above.Show me how to point to these array, how to pass them as a pointer in function.
and also how do you loop it to access each string at a time. Don’t just explain in words, I need answers as examples. Thanks alot.


May 26th, 2010 on 3:25 am
Here’s how to prototype and call functions with arrays, references and
pointers.
// one dimension with pointer
void function(int *a);
int array[10];
function(array);
// two dimensions with pointer
void function(int (*a)[20]);
int array[10][20];
function(array);
// three dimensions with pointer
void function(int (*a)[20][30]);
int array[10][20][30];
function(array);
// one dimension with reference
void function(int (&a)[10]);
int array[10];
function(array);
// two dimensions with reference
void function(int (&a)[10][20]);
int array[10][20];
function(array);
// three dimensions with reference
void function(int (&a)[10][20][30]);
int array[10][20][30];
function(array);
If your 2d array is dynamic then you need to allocate some memory for it and
use pointers. E.g.
void function(int** a);
int **array;
array = new int*[size];
for (int i = 0; i < size; ++i)
array[i] = new int[size];
function(array);