Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What are formal parameters and real parameters
What are formal parameters and real parameters
Question 1: the difference between formal participation and argumentation 1. For example, if you define a function void add(int a, int b), where a and b are formal parameters.

2. When making a function call, add (1, 2), which provides 1 and 2 as parameters.

Question: What do formal parameters and real parameters mean in JAVA? Formal parameters are formal parameters, whose names can be arbitrary, and the types of arguments should be the same as their data types.

Question 3: What are formal parameters and real parameters in C language? For example, you define a function int max(int a, int b){...}

Here a and b are formal parameters, and then you will call the max function, such as:

void main()

{

int c,int d;

.....

max(c,d);

}

Here c d is a real parameter.

The so-called formal parameters are the parameters in the semantic body of the function.

The so-called arguments are the parameters actually passed to the function when calling the function.

Question 4: What is the difference between formal parameters and real parameters in C language? Formal parameters and actual parameters

The parameters of a function are divided into formal parameters and real parameters. In this section, the characteristics of formal parameters and real parameters and their relationship will be further introduced. Formal parameters appear in the function definition and can be used in the whole function body, but they cannot be used without a function. The independent variable appears in the main tone function, and the independent variable cannot be used after entering the tuned function. The function of formal parameters and real parameters is to transmit data. When a function call occurs, the calling function transfers the value of the real parameter to the formal parameter of the called function, thus realizing the data transfer from the calling function to the called function.

The formal parameters and arguments of a function have the following characteristics:

The 1. parameter variable allocates memory cells only when called, and releases the allocated memory cells at the end of the call. Therefore, formal parameters are only valid inside the function. After the function call ends and returns to the tonic function, the parameter variable can no longer be used.

2. Parameters can be constants, variables, expressions, functions, etc. No matter what quantity the argument is, there must be definite values when making a function call in order to pass these values to the formal parameters. Therefore, we should use assignment, input and other methods in advance to get the definite value of real parameters.

3. The number, type and order of real parameters and formal parameters should be strictly consistent, otherwise there will be an error of "type mismatch".

4. The data transmission in the function call is unidirectional. In other words, you can only pass the value of the argument to the parameter, but not the value of the parameter. Therefore, during the function call, the value of the formal parameter will change, but the value in the actual parameter will not change.

An example can illustrate this problem.

Master ()

{

int n;

Printf (input number \ n);

scanf(%d,& ampn);

s(n);

printf(n=%d\n,n);

}

Integer s (integer n)

{

int I;

for(I = n- 1; I>= 1; I-)

n = n+I;

printf(n=%d\n,n);

}

A function S is defined in this program, and its function is to find the value of ∑ni. Enter the value of n in the main function, and pass it as an argument to the formal parameter n of the S function when calling (note that in this example, the identifiers of formal parameter variables and argument variables are both n, but they are two different quantities with different scopes). Use the printf statement to output the value of n once in the main gong number, which is the value of the real parameter n. In the function S, also use the printf statement to output the value of n once, which is the final value of n 0 obtained by the formal parameter. Judging from the running situation, the input value of n is 100. That is, the value of parameter n is 100. When this value is passed to the function S, the initial value of the formal parameter n is also 100, and the value of the formal parameter n becomes 5050 during the execution of the function. After returning to the main function, the value of the output parameter n is still 100. It can be seen that the value of real parameters does not change with the change of shape parameters.

Question 5: What are formal parameters and real parameters in C language? You'd better give an example When defining a function:

Void a(int a, int b) where a and b are formal parameters.

When calling a (), we need to write like this:

A (2,5) Here, 2 and 5 are real arguments.

Question 6: What are formal parameters and real parameters? Generally speaking, formal parameters are variables in the parameter table when defining a function, and real parameters are variables given to the function when calling the function (written in parentheses after the function name).

Question 7: What do formal parameters and real parameters mean in C language? What is the difference? A formal parameter is a formal parameter, and a variable represents everyone. Real parameters are actual parameters, and exact numerical values are used instead of formal parameters, which can be expressions. The number, type and order of actual parameters and formal parameters should be the same. If not, the system will force conversion, which will cause data loss. The transfer of real parameters to formal parameters is the transfer of values.

This value is the calculation result of real parameter expression, which can be constant value, variable value, array element, function value, etc. If the parameter is an array name, it passes the value of the address. For example:

Double power(double x, int n) defines a double precision parameter.

Power (3.0, 5) call

X n is a formal parameter, and 3.0,5 is a real parameter. If the integer multiple power (int x, int n) is defined above and the power (3.3,5) is called below, then 3.3 in the independent variable will be converted into 3, and some data will be lost.

Question 8: What do formal parameters and real parameters mean in C language? The function parameters given in the function declaration are formal parameters.

The function parameter passed in the function call expression is an actual parameter.

Question 9: What is the difference between real parameters and formal parameters in 9:c+++? Formal parameters: parameters in the function declaration.

Argument: the parameter passed in when calling the function.