The difference between formal participation and actual parameters

1. The formal parameter variable allocates the memory unit only when it is called . At the end of the call, the allocated memory unit is released immediately. Therefore, the formal parameters are only valid inside the function . After the function call ends and returns to the main calling function, the formal parameter variable can no longer be used. 
2. The actual parameters can be constants, variables, expressions, functions, etc. No matter what type of actual parameters are, when the function is called , they must have definite values ​​so that these values ​​can be passed to the formal parameters . Therefore, methods such as assignment and input should be used in advance to obtain a certain value for the parameter.
3. The actual parameters and formal parameters should be strictly consistent in number, type and order, otherwise an error of type mismatch will occur.
4. In the general call-by-value mechanism, only the actual parameter can be passed to the formal parameter, and the value of the formal parameter cannot be passed to the actual parameter in reverse. Therefore, during the function call, the formal parameter value changes, but the value in the actual parameter does not change. In the call -by-reference mechanism, the address of the actual parameter reference is passed to the formal parameter, so any change that occurs on the formal parameter actually occurs on the actual parameter variable.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324640939&siteId=291194637