ProgrammingVery hardTCS NQT · Infosys
#define MAX(a,b) ((a)>(b)?(a):(b)). With int i = 7; int m = MAX(i++, 5); what are m and i afterwards?
- A. m = 7, i = 8
- B. m = 8, i = 9
- C. m = 8, i = 8
- D. m = 7, i = 9
Correct answer: B. m = 8, i = 9
The condition evaluates i++ once (7 > 5, and i becomes 8). The selected branch evaluates i++ again, which yields 8 and makes i 9. A side-effecting macro argument can run more than once.
More C Programming questions
- qsort is called on int arr[5] = {-7, 3, -2, 5, -4} with a comparator that returns (abs(a) > abs(b)) - (abs(a) < abs(b)) on the two…
- A qsort comparator is written as return (const int )a - (const int )b; Which statement is true?
- Which statement about the standard library function qsort is true?
- char names[] holds char pointers to strings and must be sorted alphabetically with qsort(names, n, sizeof names[0], cmp). Which comparator…
- int f(int n) { return n < 2 ? 1 : f(n - 1) + f(n - 2); } How many calls to f happen in total, counting the first call, when evaluating f(5)?
- A recursive Tower of Hanoi solution moves n disks, one at a time, with the rule that a larger disk never sits on a smaller one. How many…