Twofold recursion, over both arrays - see the comments:
// recursives
void find_matches(int *arr, int *bee, int *matches, int current_position_in_arr);
void find_matches_in_bee(int *arr, int *bee, int *matches, int current_position_in_arr, int current_position_in_bee);
// wrapper
void find_matches(int *arr, int *bee, int *matches) {
find_matches(arr, bee, matches, 0);
}
// outer loop : iterate over 'arr'
void find_matches(int *arr, int *bee, int *matches, int current_position_in_arr) {
// check where arr[current_position_in_arr] is present in bee
find_matches_in_bee(arr, bee, matches, current_position_in_arr, 0);
// "next iteration of loop" - we check the next element in arr
if (current_position_in_arr + 1 < length) {
find_matches(arr, bee, matches, current_position_in_arr + 1);
}
}
// inner loop : iterate over 'bee'
void find_matches_in_bee(int *arr, int *bee, int *matches, int current_position_in_arr, int current_position_in_bee) {
// do your business magic
if (arr[current_position_in_arr] == bee[current_position_in_bee]) {
....
}
// "next iteration of loop" - we check the next element in bee
if (current_position_in_bee + 1 < length) {
find_matches_in_bee(arr, bee, matches, current_position_in_arr, current_position_in_bee + 1);
}
}
Invoke the same way as before:
find_matches(arr, bee, matches);
The lesson here is that you can replace stuff like:
int *array;
for (int i = 0; i < LEN; ++i) {
f(array[i]);
}
with
void f(int *array) {
f_inner(array, 0);
}
void f_inner(int *array, int position) {
// business logic on array[position]
// iteration step
if (position + 1 < LEN) {
f_inner(array, position + 1);
}
}