This is the function from where I am returning the array pointer.
#include<bits/stdc++.h>
using namespace std;
int *mergeArray(int a[], int b[], int as, int bs){
int* temp=new int[as+bs];
int i{0}, j{0}, k{0};
while(i<as&&j<bs){
if(a[i]<b[j]) temp[k++]=a[i++];
else temp[k++]=b[j++];
}
while(i<as) temp[k++]=a[i++];
while(j<bs) temp[k++]=b[j++];
return temp;
}
This is my main function. I am merging the sorted array by calling the mergeArray function. I want to find the length of the main array after merging. When I am trying to find the array size but I am getting 8 as output but the value should be 14. When I am using sizeof am getting size of int data type divide by first data of merged array i.e ((size of int data type)/arr[0]);
int main(){
int arr1[]={3, 6, 8, 10, 15};
int arr2[]={1, 5, 12};
int arr3[]={4, 8, 15, 16};
int arr4[]={2, 6};
int s1=sizeof(arr1)/sizeof(arr1[0]);
int s2=sizeof(arr2)/sizeof(arr2[0]);
int s3=sizeof(arr3)/sizeof(arr3[0]);
int s4=sizeof(arr4)/sizeof(arr4[0]);
int range[min(s1,min(s2, min(s3, s4)))*4];
int *arr= mergeArray(arr1, (mergeArray(arr2, (mergeArray(arr3, arr4, s3, s4)), s2, s3+s4)), s1, s2+s3+s4);
cout<<sizeof(arr)/sizeof(arr[0])<<" ";
}