Nowadays, many universities have made C language a compulsory course. It is relatively difficult to master C language. In addition to thinking more in daily life, you also need to do daily summaries. When learning C language, there are two different parameters, one is formal parameter and the other is actual parameter. The scope of their use is different. There is a big difference between formal parameters and actual parameters, but many people do not understand the difference between the two. The difference between formal parameters and actual parameters Formal parameters appear in the function definition and can be used throughout the function body, but cannot be used outside the function. The actual parameter appears in the calling function. After entering the called function, the actual parameter variable cannot be used. The function of formal parameters and actual parameters is to transfer data. When a function call occurs, the calling function transfers the value of the actual parameter to the formal parameter of the called function, thereby realizing data transfer from the calling function to the called function. 1. Memory units are allocated to formal parameter variables only when they are called, and the allocated memory units are released immediately at the end of the call. Therefore, the formal parameters are only valid inside the function. After the function call ends and returns to the calling function, the formal parameter variable can no longer be used. 2. Actual parameters can be constants, variables, expressions, functions, etc. No matter what type of quantity the actual parameters are, they must have definite values when calling the function so that these values can be passed to the formal parameters. Therefore, the actual parameters should be assigned and inputted in advance to obtain certain values. 3. The actual parameters and formal parameters should be strictly consistent in quantity, type and order, otherwise a "type mismatch" error will occur. 4. The data transfer that occurs in a function call is one-way. That is, the value of the actual parameter can only be transferred to the formal parameter, but the value of the formal parameter cannot be transferred back to the actual parameter. Therefore, during the function call, the value of the formal parameter changes, but the value of the actual parameter does not change. 5. When the formal parameter and the actual parameter are not pointer types, when the function is running, the formal parameter and the actual parameter are different variables. They are located in different positions in the memory. The formal parameter copies the content of the actual parameter. When the function ends, the formal parameter is released, and the content of the actual parameter does not change. |
<<: What is the best thing to soak with honeysuckle?
>>: What is the difference between Codonopsis and Ginseng?
In fact, everyone is familiar with Luo Han Guo. I...
Produced by: Science Popularization China Produce...
Before we know it, the Grain Rain solar term is a...
There are significant differences in behavior and...
Everyone is familiar with Yun Shigen, of course s...
As people's living standards improve, they pa...
Now in our daily life, when many people are sick,...
Want to be energetic all day? A cup of strong cof...
Although wolfberry is loved and recognized by man...
Can moldy Cordyceps sinensis be eaten? A friend c...
This work is original to "Science Populariza...
The world is full of wonders, and Chinese medicin...
For most women, they are relatively worried about...
recently Two records for trees were broken First,...
Long johns, heaters, and hot packs... these magic...