You can specify a function that has a variable number of parameters. The most
common example is printf() . To tell the compiler that an unknown number of
arguments may be passed to a function, you must end the declaration of its
parameters using three periods. For example, this prototype specifies that func()
will have at least two integer parameters and an unknown number (including 0)
of parameters after that.
int func(int a, int b, ...);
This form of declaration is also used by a function's definition.
Any function that uses a variable number of parameters must have at least one
actual parameter. For example, this is incorrect:
int func(...); /* illegal */
C C++ Source Codes, C C++ Practical examples ,C C++ tutorial ,Your best resource for Learning C and C++
Showing posts with label Variable-Length. Show all posts
Showing posts with label Variable-Length. Show all posts
Wednesday, September 29, 2010
Monday, September 27, 2010
Declaring Variable-Length Parameter Lists
You can specify a function that has a variable number of parameters. The most
common example is printf() . To tell the compiler that an unknown number of
arguments may be passed to a function, you must end the declaration of its
parameters using three periods. For example, this prototype specifies that func()
will have at least two integer parameters and an unknown number (including 0)
of parameters after that.
int func(int a, int b, ...);
This form of declaration is also used by a function's definition.
Any function that uses a variable number of parameters must have at least one
actual parameter. For example, this is incorrect:
int func(...); /* illegal */
common example is printf() . To tell the compiler that an unknown number of
arguments may be passed to a function, you must end the declaration of its
parameters using three periods. For example, this prototype specifies that func()
will have at least two integer parameters and an unknown number (including 0)
of parameters after that.
int func(int a, int b, ...);
This form of declaration is also used by a function's definition.
Any function that uses a variable number of parameters must have at least one
actual parameter. For example, this is incorrect:
int func(...); /* illegal */
Subscribe to:
Posts (Atom)