Example Analysis of placeholder parameters and default parameters in C++
This article will explain in detail the sample analysis of the placeholder parameters and default parameters in C++. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
1, default parameter
In C++, the parameters in the function's parameter list can have default values.
Syntax: return value type function name (parameter = default)
Note: 1 set default parameters from left to right. 2 default parameters cannot be redefined
Code example:
Int test (int a, int baked 10, int cased 10) {return a + b + c;}
Back10 and cym10 are the default parameters of the function. When no values are assigned to b and c, the default parameters are used
Use
There are two things to note when using default parameters:
(1) when setting default parameters, you must set them from left to right.
Since the default value is set for the first parameter from left to right, the default parameter is set after it. You can set it all or none at all.
Code example:
Int test02 (int a mint int breco int citation 10 int daub 20 reel int fame 30) {return a + b + c + d + f;}
(2) default parameters cannot be redefined. When you define a function and implement a function, you can only choose one of the default parameters.
Code example:
Int test03 (int a = 10, int b = 10); int test03 (int a minint b) {return a + b;} int main () {cout