“具有可变参数数量的函数”是什么意思?

时间:2010-07-12 09:29:28

标签: c variadic-functions

在C中,“具有可变数量参数的函数”是什么意思?

5 个答案:

答案 0 :(得分:3)

printf就是一个很好的例子:)

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

答案 1 :(得分:3)

这意味着一个可以接受可变数量参数的函数:

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

您可以通过以下任何方式调用上述功能:

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

答案 2 :(得分:1)

它指的是一个函数,它可以使用参数列表中的省略号(...)和va_list,va_start,va_arg等方法/宏来获取可变数量的参数。你有更具体的问题吗?

参见例如:

  

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

希望有所帮助!

答案 3 :(得分:0)

一个带有可变数量参数的函数。例如printf 签名为<return-type> <function-name>(<datatype>,...);

答案 4 :(得分:0)

它表示那些具有参数但参数数量不固定的函数(因此参数的变量no)。

相关问题