0
please explain the last line of the code
bool sorted(int arr[], int n) { if (n == 1) { return true; } bool restArray = sorted(arr + 1, n - 1); return (arr[0] < arr[1] && restArray); }
3 Answers
0
Where is the source code ?
0
you have a function named sorted. The last line contains a keyword return which gives you back something when you call/use the function somewhere. In this case the function returns true (1) or false (0) as you wrote bool sorted() in the first. The true or false will depend upon the condition you provided after the return keyword.
Hope this helps.
0
First of all - you copied the code wrong (or wrote it wrong):
arr + 1 will give u error, because arr is an array. Also, the last line is not really last, as it is working condition for the recursion in the function until it hits 1.