Principle of function parameter passing

Parameter passing, in the process of running the program, the actual parameters will pass the parameter values ​​to the corresponding formal parameters, and then implement the process of data processing and return in the function. The method has parameters passed by value, parameters passed by address and press The array passes parameters.

The formal parameter: indicates the variable name and array name in the Sub and Function process parameter tables. The process does not allocate memory for them before being called. Its function is to explain the type and shape of the independent variable and its role in the process. A formal parameter can be a legal variable name other than a fixed-length string variable, or an array name with parentheses.

The argument: the argument is the parameter value passed from the calling procedure to the called procedure when the Sub and Function procedures are called. The argument can be a variable name, an array name, a constant, or an expression. When the procedure calls the parameters, the shape participation parameters are combined by position. The corresponding variable names in the parameter table and the actual parameter table may not necessarily be the same, but their data types, parameter numbers and positions must correspond one-to-one.

Principle of function parameter passing

The equal sign, function name, parentheses, and arguments are the four components of the function.

The function "=SUM(1,2,3)", 1, 2, and 3 are the parameters of the SUM function. There are no parameters 1, 2, and 3, and the function SUM is not evaluated.

The function "=VLOOKUP(2,A:C,3,)", without parameters 2, A:C and 3, how does the function VLOOKUP look up the value of the third column in the 2 column of the A column in the A:C area?

Of course, there are also functions that do not require parameters, such as "=PI()", "=NOW()", "TODAY()", and so on.

Principle of function parameter passing

There are two ways to transfer parameters in C language: one is passed in the form of a stack, and the other is passed through a register. This time, we will only describe in detail the first method of parameter passing, and the other way is not described in detail here.

First, let's take a look at the following simple call routine:

Int Add (int a, int b, int c)

{

Return a+b+c;

}

Void main()

{

Int x =0 , y = 1, z = 2;

Int result = 0;

Result = Add(x, y, z);

Printf("Result for x+y+z %d", result);

}

With the above example, let's take a closer look at how the parameters are passed. First of all, we understand a point of knowledge, that is, the "()" operator has many meanings in the C language, such as the combination, the function caller, and so on. Then in the result = Add (x, y, z) statement is of course the function caller, so in the compile phase, the execution sequence after the function caller is triggered, starting from the last parameter, the stacking order is z- 》y-》x, until all the parameters are pressed into the call stack, and then call to the function address corresponding to Add to start execution. Then, after the execution of the stack is completed, the stack space, from top to bottom, is in the order of x-"y-"z (because the growth direction of the stack is upward, that is, the address is low, therefore, x is at the lowest address, that is, Top of the stack). Therefore, the reading and manipulation of parameters in the called function also occur on the stack.

Back Seat Headrest Pillow Phone Holder

Back Seat Headrest Pillow Phone Holder,Samsung Tablet Car Holder Back Seat,Car Back Seat Organiser With Tablets,Car Back Seat Tablet Holder

Ningbo Luke Automotive Supplies Ltd. , https://www.car-phone-holder.com

Posted on