Question.2
Compare two approaches to a MAX utility:
MAX
Macro:
#define MAX(a,b) ((a)>(b)?(a):(b))
constexpr:
constexpr int max_val(int a, int b) { return (a > b) ? a : b;
}
A developer calls MAX(3.14, 2) and max_val(3.14, 2). What happens?
MAX(3.14, 2)
max_val(3.14, 2)
Select Answer
Both return 3.14
3.14
The macro returns 3.14 (no type checking); the constexpr function truncates 3.14 to 3 (int parameter) -- the compiler may warn about narrowing
constexpr
3
Both return 3
The constexpr version fails to compile