All mock tests are FREE till 31 December — register to save your progress

Consider the following C code:
#include<stdio.h>
int temp = 0;
int fun(int x, int y) {
  int z; temp++;
  if (y == 3) return (x*x*x);
  else {
    z = fun(x, y/3);
    return (z*z*z);
  }
}
int main() {
  fun(4, 81);
  printf("%d", temp);
}
What will be the output of the code?

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: B. 4

Explanation

Calls are made with y = 81, 27, 9, 3, and each call increments temp, so temp = 4.

More Programming Languages and Computer Graphics questions