ProgrammingHardHCL · Tech Mahindra · C placement

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 inc(int x) { return x + 1; } int dec(int x) { return x - 1; } int main(void) { int (*ops[2])(int) = {inc, dec}; printf("%d %d", ops[0](5), ops[1](5)); return 0; }

  1. A. 4 6
  2. B. 6 6
  3. C. 5 5
  4. D. 6 4

Correct answer: D. 6 4

An array of function pointers holds inc at index 0 and dec at index 1; calling each with 5 gives 6 and 4.

More C Programming questions

Exams that ask this topic