The best example of variable-length argument lists function is printf ()
The proper declaration for printf () is
Int printf (char * format ,...)
Where the declaration... means that the number and types of these arguments may vary. The
Turn from: http://book.51cto.com/art/200902/109025.htm
transfer of 5.4.2 variable length parameters
The previous section describes how to create a function with variable-length parameters and how to read variable-length arguments, which are done
The function of variable length parameter is a function with variable number of parameters and indefinite parameter type.
It is possible to design a function with variable number of parameters and indefinite parameter types, the most common example
Usually the number of arguments we use for the C function is fixed, but it is not fixed. such as printf () and scanf (). How to implement a variadic function by yourself is a bit tricky.Our most common use is to define a macro, using printf or
Objective
In a project sucked in in order to use shared memory and custom memory pools, we define functions ourselves and MemNew automate constructors for non pod types within functions. Call the custom function where you want it MemNew . This
by J2SE 1.4, it was not possible to define a variable number of arguments in a Java program-because Java requires both the number and type of arguments (Arguments) and formal parameters (Parameters) to match each other, and the number of formal
The variable-length parameter (varargs) is provided in the JAVA5, which means that the number of parameters can be used in the method definition, with different number of parameters to invoke for the same method, such as print ("Hello");p rint
this series as effective JavaScript 's reading notes. in the Item , the paper introduces a combination of Apply variable argument list function implemented by method Average , it actually declares only an array as a parameter, but uses the Apply
How to use variable length parameters in Java
Variable-length parameters (varargs) are provided in the JAVA5, which means that the number of indeterminate parameters can be used in the method definition, and a different number of parameters can be
The principle of transfer of function parametersfunction parameters are accessed in memory in the form of stacks, from right to left into the stack.The parameter stores the format in memory:In the process, the stack address is allocated from high to
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.