tags:

views:

70

answers:

5

In C, what is meant by "functions with a variable number of parameters"?

+1  A: 

It refers to a function which can take a variable number of parameters using ellipses (...) in the parameter list and va_list, va_start, va_arg etc methods/macros. Do you have a more specific question about it?

See for example:

http://www.cplusplus.com/reference/clibrary/cstdarg/va_arg/

Hope that helps!

Kieren Johnstone
Thanks all , but can anybody explain it with a simple example?
Renjith G
+3  A: 

printf is a nice example of that :)

printf("Call with no other variables");
printf("Call with %d variables", 1);
printf("Call with %d variables. The other variable: %d", 2, 5);
WoLpH
A: 

A function which takes variable number of arguments. Eg printf The signature is as <return-type> <function-name>(<datatype>,...);

Praveen S
Incorrect. Such functions must have at least one non-... argument before the ...
R..
@R - Thanks edited it. +1 for reporting.
Praveen S
+3  A: 

It means a function that can accept a variable number of arguments:

void myprintf(const char *fmt, ...)
    {
    }

You can call the above function in any of the below manners:

myprintf("This is %d", 1);
myprintf("%d out of %d", 1, 2);
myprintf("%d/%d %c", 1,2, 'c');
kgiannakakis
A: 

It denotes those functions, which have parameters but the number of parameters are not fixed (hence variable no of params).

Sadat