开发者

What is meant by "functions with a variable number of parameters"?

开发者 https://www.devze.com 2023-01-06 15:46 出处:网络
In C, what is meant by \"开发者_开发知识库functions with a variable number of parameters\"?printf is a nice example of that :)

In C, what is meant by "开发者_开发知识库functions with a variable number of parameters"?


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);


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');


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!


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消