Asked
Active
Viewed 32 times
-2
-
5Copy code to post, and don't attach an image of it. – Tony Tannous Jun 14 '20 at 09:26
-
1Your merge expects an int* as it's first parameter while you are sending an int. The order of parameters passed to a function is important. – Tony Tannous Jun 14 '20 at 09:29
-
2The order and number of arguments in the call to `merge(n1, n2, arr1, arr2)` doesn't seem to match the definition of `merge(int *arr1, int n1, int *arr2, int n2, int *ans)` in the screenshot. – anjsimmo Jun 14 '20 at 09:33
2 Answers
0
You need to create a pointer to you array, and then give it to merge function. Or replace merge(*int arr1, int n1, *int arr2, int n2, *int ans) on links to array

Dies_Irae
- 37
- 4
0
merge
is declared as void merge(int*, int, int*, int, int*)
. But in main
you call it as
merge(n1, n2, arr1, arr2);
with int, int, int*, int*
(5th parameter is missing). You need to allocate some memory for the parameter ans
. Presumably something like
auto arrAns = new int[n1 + n2];
(don't forget to delete[]
it at the end!) and pass them in the correct order:
merge(arr1, n1, arr2, n2, arrAns);
Finally some notes:
- Why not
int arrAns[n1 + n2];
? Because VLAs are not part of the C++ standard - Whenever possible use standard containers like
std::vector
, instead of manual memory management.

Lukas-T
- 11,133
- 3
- 20
- 30