Sunday, March 3, 2019

Variable arguments in C

Variable arguments can be passed to a function in C. The best example for this is the inbuilt printf function. For printf the first argument is a character array and variable number of arguments after that. This is implemented using macros within the stdarg header. When parameters are passed to a function , its copied to a stack created for that function. va_list and va_arg and va_end are macros which help traverse thru this stack. This is partial implementation of your own printf function.

No comments:

Post a Comment