Use of default and placeholder Parameters

Source: Internet
Author: User

Default parameters:

1: In the parameter list, only the parameters at the back of the list can be defaulted. That is to say, a non-default parameter cannot be followed by a default parameter;

2: Once a default parameter is used in a function call, all parameters following this parameter must be default;

3: default parameters can only be placed in the function declaration, usually in a header file. The compiler must know the default value before using this function. For the convenience of reading, you can put some default comment values in the function definition.

Void FN (INT x/* = 0 */){}

 

Placeholder parameters:

Placeholder parameters can be used in function declaration as follows:

Void F (int x, Int = 0, float = 1.1 );

The purpose is to modify the function definition in the future without modifying all function calls. Of course, a parameter with a name can achieve the same purpose, however, if the defined parameter is not used in the function body, most compilers will give a warning message;

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.