passing a dubble array to a function
how do you pass on a dubble array like this
char array[2] [80] = {{"text 1"}, {"text2}} ;
function_text(char) ; // <= I want to pass the whole array to this function
and no pointers pls
thanx in advance for any help...
void FuntTakingA2DArray(char arr[2][80])
{
cout<< arr[0];
cout<< arr[1];
}
void main()
{
char arr[2][80]={{"text1"},{"text2"}};
FuntTakingA2DArray(arr);
}
the name of an array contains the base address of the array which we are passing to the function . As u mentioned no pointers happy!
thanx for the quick answer but I forgot to say something :
what if I don''t know how big the array will be?
it could also be :
char array[2] [80] = {{"text 1"}, {"text2}, {"text 3"}} ;
again thanx in advance for any replies
what if I don''t know how big the array will be?
it could also be :
char array[2] [80] = {{"text 1"}, {"text2}, {"text 3"}} ;
again thanx in advance for any replies
If you don''t know the sizes, you''ll have to use pointers. Or a language which is a little fancier about its array implementation, such as Java. Or perhaps some sort of library. Sorry, I don''t remember how to do it in C++, or C for that matter, offhand - I pretty much never had to deal with such arrays in my code.
In that last example, you''ll need to use [3][80] rather than [2][80], of course.
It''s spelled "double", and you''re talking about a 2-dimensional array, not a "double array" which one would normally understand to mean an array of doubles (double-precision floating-point values).
In that last example, you''ll need to use [3][80] rather than [2][80], of course.
It''s spelled "double", and you''re talking about a 2-dimensional array, not a "double array" which one would normally understand to mean an array of doubles (double-precision floating-point values).
if it''s an array of null terminated strings you could do this:
or else i think you have to pass both dimensions to the function?
func(const char* array[], int size){for(int i=0; i<size; i++){cout << array;}}
or else i think you have to pass both dimensions to the function?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement