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); }

7th Oct 2021, 1:27 PM
Praveen
Praveen - avatar
3 Answers
0
Where is the source code ?
7th Oct 2021, 1:35 PM
zexu knub
zexu knub - avatar
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.
7th Oct 2021, 2:28 PM
Kashyap Kumar
Kashyap Kumar - avatar
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.
8th Oct 2021, 2:59 PM
Dennis Torhov
Dennis Torhov - avatar