Can anyone please explain me this part of a code:
int ret = leftIndex > middleIndex - 1?leftIndex:middleIndex - 1;
I have not seen such a combination yet or putting a condition into integer variable in this way.
Thank you.
Can anyone please explain me this part of a code:
int ret = leftIndex > middleIndex - 1?leftIndex:middleIndex - 1;
I have not seen such a combination yet or putting a condition into integer variable in this way.
Thank you.
The ?: is called a Tertiary Operator. It takes the form:
condition ? true_result : false_result
Which translates to:
if(condition){
true_result;
} else {
false_result;
}
Your line of code translates into this:
if(leftIndex > middleIndex - 1){
int ret = leftIndex;
} else {
int ret = middleIndex - 1;
}