Function parameter expansion
-
It can provide a default value in the C ++ function declaration parameters
-
When the function call does not provide the value of the parameter, the default value
The default rule function parameters
-
The default value of the parameter must be from right to left provided
-
Use the default value when the function call, then the following parameters must use the default value
#include " stdio.h " int Mull ( int X = 2 ); int the Add ( int X = . 1 , int Y = 2 , int Z = . 3 ); // function parameter placeholder int FUNC ( int X, int ) { return x; } int main () { printf("%d\n", mull()); //x=2 printf("%d\n", mull(3)); //x=3 printf("%d\n", mull(-1)); //x=-1 printf("%d\n", add()); //x=1,y=2,z=3 printf("%d\n", add(0)); //x=0,y=2,z=3 printf("%d\n", add(2,3)); //x=2,y=3,z=3 printf("%d\n", add(4,5,6)); //x=4,y=5,z=6 func(1,2); return 0; } int mull(int x) { return x*x; } you add ( you get, you y, you z) { return x + y + z; }
Placeholder function parameter
-
It may be provided as a function of positional parameters in C ++
-
Placeholder parameters only parameter type declaration, but did not declare the parameter name
-
Under normal circumstances, can not be used in the functions that parameter placeholder
Meaning placeholder function parameter
-
Placeholder parameters used in conjunction with default parameters
-
Not compatible with standard programs written in C language may arise
In the C language void func (); and a void func (void); inequivalent
void func in the C ++ language (); and a void func (void); Equivalent