C Interview :Variable-Length Argument Lists

C Interview :Variable-Length Argument Lists
1.How can I write a function that takes a variable number of
arguments?

A:Use the header.

2.How can I write a function that takes a format string and a
variable number of arguments, like printf, and passes them to
printf to do most of the work?

A:Use vprintf, vfprintf, or vsprintf.

3.How can I discover how many arguments a function was actually
called with?

A:Any function which takes a variable number of arguments must be
able to determine from the arguments themselves how many of them
there are.

4.How can I write a function which takes a variable number of
arguments and passes them to some other function (which takes a
variable number of arguments)?

A:In general, you cannot.

No comments:

 
Top Blogs