ProgrammingHardCognizant GenC · C · Advanced

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 dbl(int x) { return x * 2; } int call_twice(int (*f)(int), int x) { return f(f(x)); } int main(void) { printf("%d", call_twice(dbl, 3)); return 0; }

  1. A. 6
  2. B. 9
  3. C. 12
  4. D. 18

Correct answer: C. 12

f(f(x)) applies dbl twice: dbl(3)=6, then dbl(6)=12.

More C Programming questions

Exams that ask this topic