>
means greater than, equal in all languages and in mathematics (although it is usually a statement and in programming it is a question that will generate a Boolean result. In this case you are asking if the value of left
is greater than the value of right
.
The result will decide what to do with the next operator that is ternary (at the moment the only one like this), ie it has three parts. Its name is conditional operator. Then the value of the second part (after the ?
will be the result of every expression if the previous condition is true. If it is false the result will be the last part, that is, what is after the :
. This result will be saved in larger
.
So he’s like a if
, but it’s an expression.
This code could be written like this:
int left = height(p->left);
int right= height(p->right);
if (left > right) return 1 + left;
else return 1 + right
I put in the Github for future reference.
The
cond? case_true: case_false
is the ternary operator. Returnscase_true
case the condition incond
be true, returncase_false
otherwise. The condition is ifleft > right
, number of the left greater than the number of the right. It returns the number of the left if true, and the number of the right if not. I mean, take the big one– Jefferson Quesado