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…

1505Medium 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 (*fp[2])(int, int) = {add, mul};
    printf("%d %d", fp[0](3, 4), fp[1](3, 4));
    return 0;
}
  • A12 7
  • B7 7
  • C7 12
  • D12 12
Correct answer: C

Explanation

fp[0] points to add (3 + 4 = 7) and fp[1] points to mul (3 × 4 = 12).

Discussion 0

Nobody has replied yet. Start the discussion!