What does "..." mean in a function declaration of C?

What does it mean?

void message(int x, int y, ...) 

I do not understand what ... is. Can someone explain?

+6
c function variadic-functions
source share
5 answers

Uncertain / variable number of parameters. To process such a function, you should use functions like va_list and va_start, va_arg and va_end:

An example taken from here :

  #include <stdlib.h> #include <stdarg.h> #include <stdio.h> int maxof(int, ...) ; void f(void); main(){ f(); exit(EXIT SUCCESS); } int maxof(int n args, ...){ register int i; int max, a; va_list ap; va_start(ap, n args); max = va_arg(ap, int); for(i = 2; i <= n_args; i++) { if((a = va_arg(ap, int)) > max) max = a; } va_end(ap); return max; } void f(void) { int i = 5; int j[256]; j[42] = 24; printf("%d\n",maxof(3, i, j[42], 0)); } 

More here

+5
source share

... denotes a variable list of arguments that can be accessed through va_arg, va_end and va_start .

+8
source share

You have defined a function message somewhere that takes at least two arguments of type int, and then some optional arguments, indicated by "...". ( printf is another function that takes optional arguments).

Optional arguments can be accessed using va_ * functions.

+3
source share

... represents the final argument passed as an array or as a sequence of arguments.

+2
source share

This is a formal argument variable parameter. Based on the syntactic perspective, you can pass a variable number of parameters (at least two, which are x and y, but even more).

0
source share

All Articles