Exercise 25. Variable Argument Functions

In C, you can create your own versions of functions like printf and scanf by creating a variable argument function, or vararg function. These functions use the header stdarg.h, and with them, you can create nicer interfaces to your library. They are handy for certain types of builder functions, formatting functions, and anything that takes variable arguments.

Understanding vararg functions is not essential to creating C programs. I think I’ve used it maybe 20 times in my code in all of the years I’ve been programming. However, knowing how a vararg function works will help you debug the programs you use and gives you a better understanding of the computer.

ex25.c

  1   2

Get Learn C the Hard Way: A Clear & Direct Introduction To Modern C Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.