Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
How to pass an array of string as pointers to a funtion?
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.
2 Answers
- 1 decade agoFavorite Answer
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);
- melanconLv 44 years ago
seem into the "new" operator because it pertains to arrays, then use it to allocate a clean character array for each get entry to in an array of regulations-to-char. this would artwork: char* sentence[ 20 ]; .... sentence[ i ] = new char[ one hundred ]; // undecided of the syntax right here. desire that helps.