I wanted to compare two arrays. I have set a variable as true and it gets false, when any element in an array does not match. I want to return that variable, which is a boolean, but it does not return that. Why is that?
bool compare_arr(int arr1[], int len_arr1, int arr2[] ,int len_arr2){
cout << "Compare the two Arrays"<< endl;
bool result = true;
for(int x = 0; x < len_arr1; x++)
{
if(arr1[x]==arr2[x])
{
continue;
}
else
{
result = false;
break;
}
}
return result;
}
int main()
{
int arr1[] = {1,2,3,4};
int len_arr1 = sizeof(arr1)/sizeof(arr1[0]);
int arr2[] = {1,2,3,4};
int len_arr2 = sizeof(arr2)/sizeof(arr1[0]);
compare_arr(arr1,len_arr1,arr2,len_arr2);
return 0;
}