Related Articles

Related Articles

C | Functions | Question 11
  • Difficulty Level : Easy
  • Last Updated : 23 Jan, 2014
filter_none

edit
close

play_arrow

link
brightness_4
code

#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;
    }
    va_end(p);
    return val;
}
int main()
{
    printf("%d\n", fun(4, 1, 2, 3));
    return 0;
}

chevron_right


(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 https://www.geeksforgeeks.org/how-to-count-variable-numbers-of-arguments-in-c for details.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :