All mock tests are FREE till 31 December — register to save your progress

What is the output of the following program?
#include <stdio.h>
#define SQR(x) (x*x)
int main() {
  int a, b = 3;
  a = SQR(b+2);
  printf("%d", a);
  return 0;
}

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: B. 11

Explanation

Macro expansion gives (b+2*b+2) = 3 + 6 + 2 = 11, because the argument is not parenthesised.

More Programming Languages and Computer Graphics questions