Chapter 7: Functions

Source: Internet
Author: User

1: The parameter is a variable with the scope of this function. The parameter is an expression that initializes the parameter.

2: If you need to change the real parameter content, C ++ prefers to use the reference, that is, to give it an alias; it is initialized during the call.

3: variables are referenced and must be initialized during definition. However, when a parameter is referenced, it should be understood that it is initialized only during the call, so it is determined when no definition is made; similarly, constant parameters are used.

4: The const parameter is more flexible than the non-const parameter, because the non-const Parameter Function cannot call the const real parameter and the Literal Value

5: The array cannot be a function parameter, because the array does not support copying and the array name is automatically converted to a pointer. The function has its form of parameter. In essence, the array cannot be passed.

6: note that the length limit in array 3 is meaningless because the compiler does not check the length of the array.

7: You must note that when passing parameters in an array, because its name is automatically converted to a pointer, the essence is to pass the pointer, ---- This is for non-reference type

8: When referencing, the array will not be compiled into a pointer, but will be referenced by the array itself. In this case, the array size of the parameter must be the same as that of the real parameter array. The format of the parameter must be int (& ARR) [N].

9: For the omitted parameter, va_list type, va_start, va_arg, and va_end are used; va_list is used to represent the stack, va_start is used to obtain the first parameter, and the first parameter is output to the stack; then we use va_arg to continuously obtain the data in the stack. After obtaining the data, we use va_end to indicate that the data has been obtained. For va_arg, the first parameter is the stack, and the second parameter is the data type of the obtained number; for va_start, the first parameter is the stack, and the second parameter is the first form parameter of the function to obtain the real parameter. For va_end, only one parameter is the stack.

10: note that when calling a function with the omitted symbol, the first parameter should not be a reference parameter.

11: whether the main is successful or not. If you want to be independent from the machine, use exit_failure and exit_success in the header file.

12: when the return value is not a reference, the return value is copied to the temporary object, and there can be local variables. If the return value is a reference, it is not a copy value, not a local variable; the temporary object appears at the function call.

13: The reference return value is the left value. It is understood that a temporary object is constructed at the function call, and the object is a reference of a value, which is equivalent to a reference variable and can be assigned a value; if the return value is not referenced, only a temporary object is returned. After this sentence is passed, it is automatically deregistered, so it is the right value.

14: The default real parameter. If it is specified in the declaration, this header file can be used. However, if it is specified in the definition, it only takes effect in the file source. We recommend that you include the header file.

15: inline function definitions can be defined multiple times in the header file, but only once in the same file source.

16: In the function pointer, directly referencing the function name is equivalent to obtaining the address character in the function name, but cannot be automatically converted into an address when being returned.

Chapter 7: Functions

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.