I need to create a function to create a set of integers. As I don’t know the no. of arguments, I thought of using the ellipses.
void f1(...)
{
va_list ap;
//how to initialize ap as I don't know the last actual argument as there is no such argument!!!
}
Also, is there any other way to know whether the list has ended instead of supplying a last argument with a value that denotes the end of list????
Please help!!!
Let’s rewrite your function a little.
Now, this can be invoked with:
Note, though, that the number of arguments is known at each call site. An alternative interface design specifies the number of parameters in the first argument:
However, if you need to specify an arbitrary number of arguments in a single call, then you need an interface more like:
This allows you to specify the number of items in the array.