GATE | GATE CS Mock 2018 | Set 2 | Question 35
What is output of following C – 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
filter_none
(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 http://www.geeksforgeeks.org/how-to-count-variable-numbers-of-arguments-in-c for details.
Quiz of this Question
Recommended Posts:
- GATE | GATE CS 1999 | Question 36
- GATE | GATE CS Mock 2018 | Question 39
- Top 5 Topics for Each Section of GATE CS Syllabus
- How to prepare in Last 10 days to score high in GATE?
- Aptitude | GATE IT 2006 | Question 7
- Aptitude | GATE IT 2006 | Question 8
- GATE | GATE CS 2013 | Question 1
- GATE | GATE CS 2013 | Question 3
- GATE | GATE CS 2013 | Question 4
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 6
- GATE | GATE CS 2013 | Question 7
- GATE | GATE CS 2013 | Question 8
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 65

