I came across a Question i.e passing Variable number of arguments to a function in C. The Question is in this way:
Write a function that takes a variable number of arguments representing student marks in english and returns the number of students who scored > 90 marks. E.g.: variableArguments(3, 20, 90, 98) returns 1. One value (98) is greater than 90.
First argument is number (arg_count) of student marks followed by "arg_count" number of arguments. E.g.: If first argument to function is 5, total number of arguments to function will be 6 (1 + 5).
#include<stdarg.h>
.....
.....
int variableArguments(int arg_count, ...){
//TODO
.....
.....
return 0;
}
eg:int result=variableArguments(4,87,90,98,67);
number of arguments =4
arguments=(87,90,98,67)
result value should be '1' because number of arguments >90 is one
In the prototype of the function first argument is arg_count
remaining is arguments are represented as ...
What could be the meaning of that ...
?
Here in this function it is given that arg_count
gives the number of arguments passed that we need to pass to the function while calling.
If such arguments are passed to the function, How to access the list of arguments in the definition of function ?