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; }
- A. 4 2
- B. 16 8
- C. 8 16
- 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
- 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…