Repro below. The red text on the addresses being passed in for the function args.
#include <iostream>
#include <vector>
using namespace std;
bool are_mirrored(const int arr1[], const int arr2[], int n) {
// if (!*arr1 || !*arr2) {
// if (!*arr1 && !*arr2) {return true;}
// else {return false;}
// }
arr2 = arr2 + n - 1;
for (int i = 0; i < n; ++i) {
if (*arr1 != *arr2) {return false;}
++arr1;
--arr2;
}
return true;
}
int main() {
int arr1[3] = {1, 2, 3};
int arr2[3] = {3, 2, 1};
assert(are_mirrored(arr1, arr2, 3)); // true
int arr3[3] = {1, 2, 3};
int arr4[5] = {5, 4, 3, 2, 1};
// NOTE: we are only looking at the last 3
// elements of arr2 as a subarray,
// so from the perspective of are_mirrored,
// it is operating on two arrays of size 3
assert(are_mirrored(arr3, arr4+2, 3)); // true
int arr5[3] = {5, 7, 5};
int arr6[3] = {5, 8, 5};
assert(!are_mirrored(arr5, arr6, 2)); // false
int arr7[1] = {2};
assert(are_mirrored(arr7, arr7, 1)); // true
assert(are_mirrored(arr7, arr7, 0)); // true
}
Repro below. The red text on the addresses being passed in for the function args.