Passing an Array to a function by Reference

Hi, I'm writing a small project and since I'm new to pointers I've been having troubles passing an array to a function by reference.
Say:
1
2
3
4
5
int Array_data[2]={1,2};
//and I need to pass the array above to a function "solution"
solution(&array_data);
// isn't working, say the function receives it this way
// solution( int *new_array[]) 

Please help me on this, I'm so new to Pointers
Last edited on
If you indeed mean pointers then the function should be declared as

SomeReturnType solution( int *a, int n );

and called as

solution( Array_data, 2 );

If you mean references instead of pointers then the function should be declared as

SomeReturnType solution( int ( &a )[2] );

and called as

solution( Array_data );
Last edited on
What I'm doing is this:
Instead of copying the whole array from function_1 to function_2, all I wanna do is pass the address of the array in function_1 to function_2, so that I'd be able to access and change(where needed) the content of that array in function_1 in function_2.
I showed you examples of declarations and calling such functions.
Thanks, I think I've found a solution to what I was trying to do. I never knew C++ does not allow an array to be passed as argument(s) to a function, it only allows you to pass a pointer to the array to the function(http://www.tutorialspoint.com/cplusplus/cpp_passing_arrays_to_functions.htm)
@Matri X I never knew C++ does not allow an array to be passed as argument(s) to a function, it only allows you to pass a pointer to the array to the function(http://www.tutorialspoint.com/cplusplus/cpp_passing_arrays_to_functions.htm)


It looks like you are not an adequate. I showed you how an array can be passed by reference.
Topic archived. No new replies allowed.