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