C supports variable numbers of arguments. But there is no language provided way for finding out total number of arguments passed. User has to handle this in one of the following ways:
1) By passing first argument as count of arguments.
2) By passing last argument as NULL (or 0).
3) Using some printf (or scanf) like mechanism where first argument has placeholders for rest of the arguments.
Following is an example that uses first argument arg_count to hold count of other arguments.
Minimum value is 6
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Functions in C/C++
- Arrays in C/C++
- What happens when a function is called before its declaration in C?
- Sequence Points in C | Set 1
- Functions that are executed before and after main() in C
- Functions that cannot be overloaded in C++
- return statement vs exit() in main()
- exit(), abort() and assert()
- What is evaluation order of function parameters in C?
- Static functions in C
- Storage for Strings in C
- What is the purpose of a function prototype?
- How can I return multiple values from a function?
- Does C support function overloading?
- Understanding "extern" keyword in C