Question discussion

What is the output of the following C program?#include #define SQR(x) x * x int main() { int i = 2; printf("%d %d", SQR(i + 1), 100 / SQR(5…

1372Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
#define SQR(x) x * x
int main() {
    int i = 2;
    printf("%d %d", SQR(i + 1), 100 / SQR(5));
    return 0;
}
  • A9 4
  • B9 100
  • C5 100
  • D5 4
Correct answer: C

Explanation

The macro does not parenthesise its argument: SQR(i + 1) becomes i + 1 * i + 1 = 5, and 100 / SQR(5) becomes 100 / 5 * 5 = 100.

Discussion 0

Nobody has replied yet. Start the discussion!