16.4 FUNCTIONS WITH VARIABLE ARGUMENTS

It is possible to have functions with variable number of arguments in C++. We have already seen function printf(). A typical call looks like

printf(“%d%d", i, j);

This example has a format string followed by two parameters. There could have been even three or four parameters. This is an excellent example of function with variable arguments.

We can have our own function of this type. In the declaration, argument list must have few (at least one) leading parameters. It is followed by an ellipsis (…). It indicates to the compiler that the present function may have variable number of arguments. While calling such a function, argument list must have leading arguments as defined. It can have any number of arguments ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.