ProgrammingHardTCS NQT · Infosys · Product Company SDE

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int add(int a, int b) { return a + b; } int mul(int a, int b) { return a * b; } int main(void) { int (*op)(int, int) = add; printf("%d ", op(3, 4)); op = mul; printf("%d", op(3, 4)); return 0; }

  1. A. 12 7
  2. B. 7 7
  3. C. 12 12
  4. D. 7 12

Correct answer: D. 7 12

op starts out pointing at add (3+4=7), is reassigned to mul, and the second call computes 3*4=12.

More C Programming questions

Exams that ask this topic