Consider the following C functions.

int tob (int b, int* arr){
  int i;
  for (i=0; b>0; i++) {
        if (b%2)  arr[i]=1;
        else      arr[i]=0;
        b = b/2;
   }
   return (i);
}
int pp(int a, int b) {
   int arr[20];
   int i, tot = 1, ex, len;
   ex = a;
   len = tob(b, arr);
   for (i = 0; i < len; i++) {
        if(arr[i] == 1)
           tot = tot * ex;
        ex = ex * ex;
    }
    return (tot);
}

The value returned by pp(3,4) is ______.

Correct Answer:

81

Solution:

pp(3, 4) means a = 3, b = 4
arr (initially contain garbage values)
tot = 1 (initially)
ex = 3
len  = tob (4, arr)

In tob(4, arr), b = 4
when i = 0, a[0] = 0
when i = 1, a[1] = 0
when i = 2, a[2] = 1
when i = 3 loop breaks and return

len = 3

Now, In pp(3, 4)
when i = 0, ex = 3*3 = 9
when i = 1, ex = 9*9 = 81
when i = 2, tot = 1*81 = 81 and ex = 81*81 = 6561

return 81