Call and parameter of C language function

Source: Internet
Author: User
Tags call by reference

If a function uses parameters, it must define a variable that accepts the parameter value.
4.3.1 formal parameters and actual parameters
The parameters that are filled in when the function is defined are called formal parameters, referred to as parameter, and they function as local variables within the function. A formal parameter is defined after the function name and before the curly braces that begin the function.
The parameter that is filled in when called, is called the actual parameter, the argument is short.
You must confirm that the defined form participates in the actual parameter type of the calling function, and also that the order in which the form participates in the argument is the same. If you do not agree, you will produce unexpected results. Unlike many other high-level languages, (it's robust, it always does something that you don't even want to do, and there's almost no run-time error checking, end
There is no range detection. As a programmer, you must tread carefully to ensure that no errors occur and run safely.
4.3.2 assignment calls and reference calls
Generally, there are two ways to pass parameters to a function. The first is called "Assignment Invocation" (call by Value), which copies the value of the parameter to the form parameter of the function. In this way, any variation of the formal parameters in the function does not affect the variable used when the call is made.
The second way to pass arguments to a function is "reference invocation" (call by reference). This method is to copy the address of the parameter to the form parameter, in which the address is used to access the actual parameters used in the call. This means that the change in formal parameters affects the variable that is used when invoked (see the following chapters for details).
In addition to a few cases, the C language uses assignment calls to pass arguments. This means that it is generally not possible to change the value of the variable used when the call is made. Take a look at example 4-9.

In this example, the parameter value passed to the function Sqr () is copied to the form parameter x, and only the local variable x is modified when the assignment statement x = x * x executes. Variable t for calling Sqr (), still holding a value of 10.
Execution procedure:
RUN <enter>
100 10
Remember, passing the function is just a copy of the parameter value. All changes that occur within a function cannot affect the variables that are used when invoked.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.