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?
Yinqishi has no odor and light taste, but as a st...
Plantain is a wild vegetable. Nowadays, people li...
Pitaya, also known as red dragon fruit or fairy h...
The living environment of Cistanche deserticola i...
Panax notoginseng powder has many functions and e...
At 20:30 on February 6, 2025, Huang Xuhua, an aca...
Have the "good things" you bought on Do...
Recently, the cat in the TV series "The Mist...
As people's health awareness increases, more ...
Narrow-leaved bamboo ginseng is a common Chinese ...
Seahorses are not common in our lives. They have ...
Silverwood bark is a kind of traditional Chinese ...