Looking at this code:
I thought that the program won't give the right maximal value if z>x and y>x, but, to my surprise, it did give the correct value. Why is that? Did the program compare Y and Z and gave the biggest value without me ordering it to do so?
After the first if
statement, max
holds the maximum of x
and y
. This maximum is then compared with z
in the second if
statement. You don't need to compere y
and z
directly due to the transitive quality of the >
operator.