Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize formal parameters and actual parameters in C language

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to realize formal parameters and actual parameters in C language". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Formal parameters and actual parameters

The parameters of the function are divided into formal parameters and actual parameters. In this section, we further introduce the characteristics of formal parameters and actual parameters and the relationship between them. Formal parameters appear in the function definition and can be used throughout the function, but cannot be used without the function. The argument appears in the main tone function, and after entering the modulated function, the real parameter variable cannot be used. The function of formal parameter and actual parameter is to transmit data. When a function call occurs, the main tone function transmits the value of the actual parameter to the formal parameter of the modulated function so as to realize the data transmission from the main tone function to the modulated function.

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

1. The parameter variable allocates memory units only when it is called, and the allocated memory units are released immediately at the end of the call. Therefore, the formal parameter is valid only within the function. The formal argument can no longer be used after the function call returns to the tone function.

two。 Arguments can be constants, variables, expressions, functions, and so on. No matter what type of quantity the arguments are, they must have definite values when making a function call in order to pass these values to the parameters. Therefore, we should use assignment, input and other methods to get the definite value of the actual parameter in advance.

3. Arguments and formal parameters should be strictly consistent in quantity, type and order, otherwise the error of type mismatch will occur.

4. The data transfer that occurs in a function call is one-way. That is, the value of the parameter can only be passed to the parameter, but the value of the parameter can not be transferred to the parameter in reverse. Therefore, during the function call, the value of the parameter changes, but the value in the argument does not change.

This problem can be illustrated.

"> # include int add (int num) {int i; for

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report