C ++ parameter transfer

Source: Internet
Author: User

Definition:

Parameters: Indicates the variable name and array name in the Sub and Function process parameters table. Before the Sub and Function process is called, no memory is allocated to them, its role is to explain the type and form of independent variables and its role in the process. The parameter can be a valid variable name other than a fixed-length string variable, or an array name with parentheses. Real Parameters: The real parameter is the parameter value that is passed to the called process from the main call process when the Sub and Function processes are called. Real parameters can be variable names, array names, constants, or expressions. When passing parameters in a process call, the form-based real parameters are combined by location. The variable names in the form-based and real-argument tables do not need to be the same, however, their data types, parameter numbers, and locations must correspond one to one. [1] Relationship: 1. The form parameter can only be a variable. The real parameter can be a constant, variable, or expression. In the defined function, the type of the parameter must be specified. 2. the number and type of real participation parameters should be the same. String and integer types can be common to each other. 3. when calling a function, if the real parameter is an array name, the first address of the array is passed to the form parameter. 4. the real parameter is transmitted to the form parameter in one direction. The shape parameter variable is used only when the function call is not performed and does not occupy the memory. After the call is completed, the memory is released. When a called function is executed, if the value of the form parameter changes, the value of the real parameter in the main function is not changed. [2] 5. the form parameter is like a symbol in the formula. The real parameter is the specific value of the symbol and must be assigned a value before the call. The call process is to combine the form with the real parameter, passing the value of the real parameter to the form parameter by calling is equivalent to inputting the value into the formula for calculation. Implementation Method: 1. PASS Parameters by value:When passing parameters by value, the value of the real parameter variable is copied to a temporary storage unit. If the value of the real parameter is changed during the call process, the real parameter variable itself is not affected, that is, the value of the real variable remains unchanged before the call. When passing parameters by value, you must add the "ByVal" keyword before the parameter name. 2. PASS Parameters by address:When parameters are passed by address, the address of the real variable is transferred to the called process. The parameters and real parameters share the same address in the memory. In the process of being called, once the value of the form parameter changes, the value of the corresponding real parameter also changes. If the real parameter is a constant or expression, Visual Basic 6.0 will process it in the "pass value" mode, and the "ByVal" keyword is not required for passing by address. [3] 3. PASS Parameters by array:In VB6.0, an array is allowed to be passed as a real parameter to the form parameter of the sub-process. The array must be passed through the address. When passing array parameters, you should pay attention to the following two aspects: ① only write the array name in the real parameter and the form parameter list, ignoring the dimension definition, but the parentheses cannot be saved. When the array is passed as the parameter, the system passes the starting address of the real parameter array to the process, so that the form parameter array also has the same starting address as the real parameter array. If the parameter is a multi-dimensional array, each dimension is separated by a comma; ② The Lbound and Ubound functions can be used to determine the lower and upper bounds of the real parameter array. Problems: As shown in the following figure:
The above code sends a message and transmits the address on the stack (to be verified ....) Bytes ------------------------------------------------------------------------------------------------------------ The following code accepts parameters: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Vc3ryb25npgokphn0cm9uzz4gpgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140613/20140613092056259.jpg" alt = ""> Cause: The transfer address is incorrect; Solution: It is enough to pass the value directly; Bytes ------------------------------------------------------------------------------------------------------------

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.