Monday, 24 December 2012

Variable Length Argument List Function: C Program

  What is a variable length argument list function in C? An excellent example is the printf( ) and scanf( ) functions provided by the header file <stdio.h>. In printf( ) and scanf ( ), the number of arguments passed is not fixed. Now the question is whether we can write such functions? The answer is yes. To write we have to use the header file <stdarg.h>. There are three macros and one data type provided by the stdarg.h header file. va_start, va_end, va_arg are the macros and va_list is the data type.
  • va_list    - This data type is used to create an data object which can hold the values passed by the function.
  • va_arg   - This macro is used to access the values stored in the data object of va_list.
  • va_start - This macro initializes the data object of the va_list type.
  • va_end   - This macro denotes the normal exit from the function by freeing the data.
Click here to download the C Program illustrating Variable Length Argument List Functions.

No comments:

Post a Comment