06 April 2011

C++ Proficiency - macro function

Define a macro function in C++ that takes parameters a and b and returns which one is greater.
1:  #define WhoIsGreater(a, b) \ 2:     ( a > b ? a : b )
How would you use the function in your program?
1:  int main() { 2:     cout << "Between 3 and 5 the greater is: " << WhoIsGreater(3,5) << endl; 3:  } Again this is not a tutorial on how to make macro functions, it's a quick refresher and an actual question asked in a technical interview.

0 comments: