Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

GATE | GATE-CS-2005 | Question 31

  • Difficulty Level : Medium
  • Last Updated : 28 Jun, 2021

Consider the following C-program:

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.




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?
(A) 8, 4, 0, 2, 14
(B) 8, 4, 0, 2, 0
(C) 2, 0, 4, 8, 14
(D) 2, 0, 4, 8, 0


Answer: (D)

Explanation: See Question 5 of https://www.geeksforgeeks.org/c-language-set-3/

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :