C++primer Study Notes (iv)--chapter 6

Source: Internet
Author: User

6.1 Function Basics

First, the structure of the function

Type functionname (Parameters list)      statement

1, the first format as above, a function must have the return value of the type, the function name functionname, as well as the parameter list in parentheses, and the contents of the main function.

2. Return value:

(1) is return, first, the return value is generally the same as the return value type, otherwise it will be converted to the return value type, but if there is no conversion method will be an error.

(2) The function of return is mainly two, one is the End function, return to the place of the call, and the other is a value.

(3) The return value type can be void, then return is only the end function of the action ~

3. Parameter list

(1) A parameter must follow a type, there can be no exception.

(2) The name of the parameter cannot be the same, and the name within the function cannot be the same as the argument list

4. Call

Remember to use the parameter type when calling to correspond to the parameter list one by one.

Second, Local Object

1. Local Variables:

This is a good understanding, that is, the definition of the variable, if within {}, then its scope is only within the scope of this {}.

2. Global variables

is defined outside of the function, then the variable can be used in any code after its definition

3. Local Static objects

This variable does not end with the end of the {}, it exists throughout the lifetime of the program, and then the definition and initialization statements of this variable are executed only once.

C++primer Study Notes (iv)--chapter 6

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.