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; }
- A. 4 6
- B. 6 6
- C. 5 5
- 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
- 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…
- 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…
- 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…
- 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…
- 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…
- 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…