3 numbers are a,d and f and s is number which will store max of those 3.
The logic is:
s = a > d ? a > f ? a : f : d > f ? d : f;
Can someone explain what it exactly means?
3 numbers are a,d and f and s is number which will store max of those 3.
The logic is:
s = a > d ? a > f ? a : f : d > f ? d : f;
Can someone explain what it exactly means?
It's probably simplest to explain with a single-ternary MAX macro:
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
So, if you want to find the max of 3 numbers, you can string these macros together
MAX(MAX(X, Y), Z)
If a > d
and a > f
, then max is a
. If a > d
but f >= a
, then max is f
. If a <= d
and d > f
, then max is d
. If a <= d
and d <= f
then max is f
.
So a ternary operator is like this. a ? b : c. If a is true it evaluates to b and if not then it evaluates to c. Apply that to your problem and if a is greater than both d and f then a is the new max. if not it checks if d > f then d is the new max. Otherwise f is the new max. Sorry for the long explanation. Hope this helps