GATE | CS | 2005 | C programming | Functions | Question 31

Last Updated :
Discuss
Comments

Consider the following C-program:

C
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);
   
  getchar();
}

What does the above program print?

8, 4, 0, 2, 14

8, 4, 0, 2, 0

2, 0, 4, 8, 14

2, 0, 4, 8, 0

Share your thoughts in the comments