Question discussion

What is the output of the following C program?#include int add(int a, int b) { return a + b; } int mul(int a, int b) { return a * b; } int…

2340Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int add(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
int main() {
    int (*op[2])(int, int) = { add, mul };
    printf("%d %d", op[0](op[1](2, 3), 4), op[1](op[0](2, 3), 4));
    return 0;
}
  • A10 20
  • B20 10
  • C9 20
  • D10 14
Correct answer: A

Explanation

op[1](2, 3) = mul = 6 and add(6, 4) = 10; op[0](2, 3) = add = 5 and mul(5, 4) = 20.

Discussion 0

Nobody has replied yet. Start the discussion!