ProgrammingHardWipro · Accenture · Capgemini pattern

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 square(int x) { return x * x; } int cube(int x) { return x * x * x; } int apply(int (*f)(int), int v) { return f(v); } int main(void) { printf("%d %d", apply(square, 4), apply(cube, 2)); return 0; }

  1. A. 4 2
  2. B. 16 8
  3. C. 8 16
  4. D. 16 16

Correct answer: B. 16 8

apply calls whatever function pointer it is given: square(4)=16, cube(2)=8.

More C Programming questions

Exams that ask this topic