question about array's merge function

i have two problems with my code:
1) inside the function im trying to create array but i cant initialize with the size i tried too....why is that?
2) even if i create the array this way int arr[10] only the first member of the new array is initialized and all the other members are empty..again..why
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>

using namespace std;

int *merge(int *a1, int n1, int *a2, int n2)
{
    int NewSize = n1 + n2;
	int i=0,i1 = 0, i2 = 0;
	int arr[NewSize]; //1'st problem
	 
	if (NewSize == 0) 
		return NULL;

	for (i = 0; i < NewSize;i++)
	{
		if (a1[i1] <= a2[i2])
		{
			arr[i] = a1[i1];
			i1++;
		}
		else
		{
			arr[i] = a2[i2];
			i2++;
		}
		cout << arr[i];
	}
	return arr;
}

int main()
{
	int arr1[] = { 1, 3, 5, 7, 9 };
	int arr2[] = { 2, 4, 6, 8, 10 };
	int* arr=merge(arr1, 5, arr2, 5);
	for (int i = 0; i < 10; i++)
	{
		cout << arr[i] <<endl;
	}
}
Topic archived. No new replies allowed.