For the following function,
int search(int n) {
return arr[n] == n ? n : arr[n] = search(arr[n]);
}
I am not very sure exactly what it's supposed to do. According to what I understand about operator precedence, my guess is that the above is equivalent to
int search(int n) {
if (arr[n] == n) {
return n;
} else {
return arr[n] = search(arr[n]);
}
}
but then it doesn't really make sense to me that the function is returning an assignment? Or am I interpreting it wrong entirely?