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; }

  1. A. 125
  2. B. 243
  3. C. 81
  4. D. 15

Correct answer: B. 243

Fast exponentiation still computes the mathematically exact power: 3^5 = 243.

More C Programming questions

Exams that ask this topic