3, Function--Modular design

Source: Internet
Author: User

"1" concept

function functions, each of which is used to implement a particular function.

"2" function declaration and definition

A declaration indicates that the function exists, and the definition indicates how the function is to run;

" the function declaration is to inform the compiling system of the information about the function (function name, functions type, function argument list) and check it at the call . "

"Function definition is the determination of function function, is a complete, independent unit of function"

Declaring the function to be called at the beginning of the file (outside of the function), the compiled system has already learned the information about the function from the external declaration, so it is not necessary to repeat the declaration in the main function.

"3" function call

When declaring a function, the parameter has no actual value, but it acts as a placeholder, called the formal parameter.

When invoking a function, the parameter must be a deterministic value, which is the real parameter that can actually work on the result.

During a call to a function, the system passes the value of the argument to the parameter of the called function, which is valid in the function call device and can participate in the operation of the function.

An argument can be a constant, a variable, or an expression; max (3,a+b);

When a function call is executed, the value of the parameter changes, but does not change the argument value of the keynote function. "The data passing of an argument to a parameter is a" value pass ", one-way pass, which can only be passed by an argument to a parameter argument and the formal parameter occupies a different storage unit in memory, and the argument cannot get the value of the parameter. 】

The compilation system only cares about and examines the number of parameters and parameter types, not the parameter names, because the argument types and formal parameter types are guaranteed to be consistent in the invocation process, regardless of the formal parameter name. Therefore, the formal parameter names can be written in the function declaration is not writable;

Returns the statement return

1) The value of the expression is fed to the calling function where the result of the function is run.

2) End the run of the function, return to the place where the function is called, and proceed to the following statement. "If a return is executed, the following statement is no longer executed"

"4" function overload

A function that has the same function is integrated into a function without having to write multiple functions with different function names, and multiple functions share a functional name .

"5" Reference

References (Referencen)

Variable data type & reference name = declared variable name;

When you use a reference to a variable, the action on the reference is like the action on the referenced variable. When declaring a variable, you must tell the computer which variable is referenced.

Using reference to pass parameters, using reference to return;

"6" Value as function parameter

Call the parameter function, need to provide an argument;

Array elements are equivalent to variables, where variables can occur, and can be replaced with array elements.

The array name can be used as an argument and a formal parameter, passing the address of the first element of the array;

The real parameter group and the shape parameter group type should be consistent.

The shape parameter group can not specify the size, when the array is defined with an empty square bracket after the array name;

3, Function--Modular design

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.