Saturday, 8 February 2014

Variable length argument in c


C – Variable length argument

      Prev                                                                                              Next

  • Variable length arguments is an advanced concept in C language offered by c99 standard. In c89 standard, fixed arguments only can be passed to the functions.
  • When a function gets number of arguments that changes at run time, we can go for variable length arguments.
  • It is denoted as … (3 dots)
  • stdarg.h header file should be included to make use of variable length argument functions.
……

Example program for variable length arguments in C:

Output:

The value from first function call = 5
The value from second function call= 14
       In the above program, function “add” is called twice. But, number of arguments passed to the function gets varies for each. So, 3 dots (…) are mentioned for function ‘add” that indicates that this function will get any number of arguments at run time.

      Prev                                                                                              Next

.


No comments:

Post a Comment