Consider the following C-program: void foo(int n, int sum) { int k = 0, j = 0;…

PYQ GATE 2005

Consider the following C-program:

void foo(int n, int sum)
{
  int k = 0, j = 0;
  if (n == 0) return;
    k = n % 10; 
  j = n / 10;
  sum = sum + k;
  foo (j, sum);
  printf ("%d,", k);
}
 
int main ()
{
  int a = 2048, sum = 0;
  foo (a, sum);
  printf ("%d\n", sum);
}

What does the above program print?

  1. A.

    8, 4, 0, 2, 14

  2. B.

    8, 4, 0, 2, 0

  3. C.

    2, 0, 4, 8, 14

  4. D.

    2, 0, 4, 8, 0

Attempted by 297 students.

Sign up free to check your answer

Sign up free

Explore the full course: Zero To Hero

Loading lesson…