Question.14
Two approaches to a MAX utility:
Macro:
#define MAX(a,b) ((a)>(b)?(a):(b))
Template:
template<typename T> constexpr T max_val(T a, T b) { return (a>b)?a:b; }
A developer calls MAX(i++, j)). What happens?
Select Answer
i is incremented once in both versions
The macro evaluates i++ twice (once in the comparison, once in the result) -- double increment; the template evaluates i++ once because function arguments are evaluated before the call
Both evaluate i++ twice
The template evaluates i++ twice