Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

GATE | GATE CS Mock 2018 | Set 2 | Question 35

  • Difficulty Level : Hard
  • Last Updated : 08 Mar, 2018

What is output of following C – Code?

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.

#include <stdio.h>
#include <stdarg.h>
int fun(int n, ...)
    int i, j = 1, val = 0;
    va_list p;
    va_start(p, n);
    for (; j < n; ++j)
        i = va_arg(p, int);
        val += i;
    return val;
int main()
    printf("%d\n", fun(4, 1, 2, 3));
    return 0;

(A) 3
(B) 5
(C) 6
(D) 10

Answer: (C)

Explanation: The function receives variable number of arguments as there are three dots after first argument.   The firs argument is count of all arguments including first.  The function mainly returns sum of all remaining arguments. See for details.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :