Functions, those things.

Source: Internet
Author: User
Tags naming convention

We often need a lot of line code in a big project, as small as a student information management system (about hundreds of lines of code), as large as a system (such as the Linux system about a few grams of code). In this case, if you put the code in a file, or even a main function, then the code is very cumbersome. In daily maintenance is very troublesome.

To solve this problem, we split the project into a few small modules that tend to use the same functionality. So put the code of the same function into a function. such as the input function (scanf) and the output function (printf), which we often use, are stored in the corresponding header file. The code of these header files is can be viewed, but need the corresponding method, do not need to know the content inside, want to know can Baidu.

The use of functions, like variables, needs to be defined and reused first. If you want to use a function first and then define the function, you need to declare the function first. Declared as: function return type function name (parameter list), parameter list can be omitted, that is: function return type function name ();. If you define the function before the main function (main function), you do not need to declare it.

Because the function is what you want it to be, define the function as a function that returns the type function name (parameter list) {The code that implements the function}. Where the parameter list cannot be omitted. The function return type can be not only any type that defines a variable, but also a null return type void. In fact, the definition of the main function (main function) can also be void, which defines the main function: void Main (). It is recommended that you do not define this now. The function name also conforms to the C language Identifier naming convention (only letters, underscores, numbers, and cannot start with a number).

The function also has the same function statement as the switch statement, the break statement in the Loop statement, and that is the return statement. In a function that has a return type, the function ends the execution of the code following the return statement, returns the called function directly, and proceeds to execute the subsequent code of the function called by the called function. and returns the data after the return. And the returned data can be assigned to a variable; The return statement returns only one data and cannot return multiple data.

The function is called by the function name (argument list), and the parameter list cannot have the data type of the parameter. We call variables in the parameter list of definitions and declarations as formal parameters, which are like variables that are defined and assigned in advance in the first line of code of the function. We also call the arguments in the argument list when the function is called the argument, the argument is not only the call function and the function of the data transfer one way, but also control the function of the back adjustment.

Because we do not speak the knowledge of pointers, so the functions you call now are not changing the values of the arguments. The special case is to call the change function when exchanging a value of two numbers (I define the name of the function interchange value as change), and a (a, b). This will not change the value of a and B.

Functions, those things.

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.