ProgrammingModerateTCS NQT · Infosys
#define SQUARE(x) x*x. What does printf("%d", SQUARE(2+3)) print?
- A. 11
- B. 25
- C. 12
- D. 9
Correct answer: A. 11
Macros substitute text, so the expansion is 2+3*2+3. Multiplication runs first: 2 + 6 + 3 = 11. A correct macro writes ((x)*(x)).
More C Programming questions
- #define MAX(a,b) ((a)>(b)?(a):(b)). With int i = 7; int m = MAX(i++, 5); what are m and i afterwards?
- 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)?