This is a part of a book I'm reading to learn Objective-C.
The following defines a macro called MAX that gives the maximum of two values:
#define MAX(a,b) ( ((a) > (b)) ? (a) : (b) )
And then there are some exercises in the book that asks the reader to define a macro (MIN
) to find the minimum of two values and another that asks to define a macro called MAX3
that gives the maximum of 3 values. I think these two definitions will look similar to MAX
, but I don't understand how the MAX
formula finds the maximum value. I mean if I just did this
int limits = MAX (4,8)
It'll just assign limits
the value of 8. What does that have to do with finding a variable's maximum value?