I am learning recursive calls implementation. i get stuck with return statements, i am trying to print an array elements by recursive call. though i print but it but i want to return it, can some body help
#include<iostream>
using namespace std;
int recursive_arr_traversal(int *arr, int length_of_array) {
if (length_of_array <= 0) {
return 0;
}
else {
return *arr; //this statement prints only one array element<endl
cout << *arr << endl;//this works fine
}
return recursive_arr_traversal(arr + 1, length_of_array - 1);
}
int main() {
int arr[10] = { 1,2,3,4,56,7,8,9,99,0 };
int length_of_array = 10;
//recursive_arr_traversal(arr,length_of_array);
cout << recursive_arr_traversal(arr, length_of_array);
return 0;
}
ifwith a return, and anelsewith a return and then lastly, you call the recursive function outside of it all. What conditions have to be true for you to get to that recursive call?