C ++ function default parameters

Source: Internet
Author: User

1. If the default value is set for a certain parameter in the function, the default value must be set for all the parameters following the parameter.

2. You can set the default value when declaring a function. You can also set the default value when defining a function. However, you cannot set the default value at the same time.

3. If a function is used before the function is defined, and the default parameters are set during the function definition, and the default real parameters are also used during the call, an error occurs during compilation, during the compilation process, it is performed in the order before and after the file. When calling a function, you only see the declared function. When declaring the function, there is no default parameter. when calling the function, the real parameter is omitted and an error occurs, if you move the defined function to the call, no error will occur.

# Include <stdio. h> // int test (int a, int B = 10, int c = 20, int d = 30); int test (int a, int B, int c, int d); int main () {test (10); return 0;} int test (int a, int B = 10, int c = 20, int d = 30) // int test (int a, int B, int c, int d) {printf ("% d", a + B + c + d); return 0 ;}

This article is from "Li Haichuan" blog, please be sure to keep this source http://lihaichuan.blog.51cto.com/498079/1303998

Related Article

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.