ProgrammingHardCompetitive coding (CP) · C internals
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 power(int b, int e) { if (e == 0) return 1; if (e % 2 == 0) { int h = power(b, e / 2); return h * h; } return b * power(b, e - 1); } int main(void) { printf("%d", power(3, 5)); return 0; }
- A. 125
- B. 243
- C. 81
- D. 15
Correct answer: B. 243
Fast exponentiation still computes the mathematically exact power: 3^5 = 243.
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…