Demonstration of using Variable number of argument
#include#include main() { int add( int nint, ... ); printf ("Sum of 4 numbers is %d", add( 4, 1,2,3,4) ); printf ("Sum of 2 numbers is %d", add( 2, 10, -2 )); } int add ( int nint, ... ) { va_list va; int total = 0 ; va = va_start (nint ); while ( nint-- ) total += va_next ( va, int ) ; va_end (va ); return total ; }
This program will add sum of all the numbers, starting from 2nd argument to nth place and 1st arguments indicate that how many arguments that is going to be passed.
Generally these are called as VARARGS (variable no. of arguments)
Code contributed by : Pradeep SP
pradeepcse23@gmail.com

