Question discussion

What is the output of the following C program?#include #define SQ(x) x * x int main() { printf("%d", SQ(2 + 3) + SQ(4)); return 0; }

1172Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
#define SQ(x) x * x
int main() {
    printf("%d", SQ(2 + 3) + SQ(4));
    return 0;
}
  • A41
  • B29
  • C25
  • D27
Correct answer: D

Explanation

The macro does no bracketing: SQ(2 + 3) expands to 2 + 3 * 2 + 3 = 11 and SQ(4) = 16, so the result is 27.

Discussion 0

Nobody has replied yet. Start the discussion!