Formal parameters and actual parameters are concepts in function calls. Formal parameters are used to receive actual data, and actual parameters are used to pass actual data. The formal parameters are located in the function header, and the actual parameters are located when the function is called; the formal parameters and the actual parameters establish a one-way relationship, and the actual parameters can modify the formal parameters but not vice versa; the scope of the formal parameters is limited to the function but the actual parameters are independent of the function; data type The upper formal parameter must specify a clear type, and the actual parameter type must be compatible with the formal parameter.
Formal parameters and actual parameters
In C language, formal parameters and actual parameters are involved in function calls Important concepts. There are obvious differences between them:
Meaning
Position
Association
Scope
Data type
Example
The following function definition:
void print_name(char *name);
Among them,name
is a formal parameter and is a character pointer .
When calling this function, you can pass an actual parameter as follows:
char *myName = "John Doe"; print_name(myName);
In this example,myName
is the actual parameter passed to the function. It is associated with the formal parametername
, allowing the function to access and print the string "John Doe".
Note:
The above is the detailed content of The difference between formal parameters and actual parameters in C language. For more information, please follow other related articles on the PHP Chinese website!