Rabu, 02 Desember 2015

stdarg.h in C

Hello readers!

i want to show you about stdarg.h in C.

stdarg.h



The stdarg.h header defines a variable type va_list and three macros which can be used to get the arguments in a function when the number of arguments are not known i.e. variable number of arguments.A function of variable arguments is defined with the ellipsis (,...) at the end of the parameter list.

stdarg.h types:
- va_list (type for iterating arguments)

stdarg.h macros:
- va_start (start iterating arguments with a va_list)
- va_arg (retrieve an argument)
- va_end (free a va_list)
- va_copy (copy contents of one va_list to another)

Library macros:
- void va_start(va_list ap, last_arg)
  This macro initializes ap variable to be used with the va_arg and va_end macros. The last_arg is the last known fixed argument being passed to the function i.e. the argument before the ellipsis.

- type va_arg(va_list ap, type)
  This macro retrieves the next argument in the parameter list of the function with type type.

- void va_end(va_list ap)
  This macro allows a function with variable arguments which used the va_start macro to return. If va_end is not called before returning from the function, the result is undefined.

Example:



That's the stdarg.h in C. Hope this will help you. Thanks! :D
nb: Some source that really helps me very much (recommended):
http://www.tutorialspoint.com/c_standard_library/stdarg_h.htm https://en.wikipedia.org/wiki/Stdarg.h




Tidak ada komentar:

Posting Komentar