Gate CS-2005 Question Paper With Solutions

Q. 31 Consider the following C-program:

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

int main() {
    int a = 2048, sum = ;
    foo(a, sum);
    printf("%d\n", sum);
}

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:

Gate CS-2005 Question Paper With Solutions

Learn More:   Gate CS-2008 Question Paper With Solutions

LEAVE A REPLY

Please enter your comment!
Please enter your name here