C Language Learning Sixth chapter

Source: Internet
Author: User

Start trying to change today!

Today to learn about functions, a major part of C language.

First, let's talk about why we use functions. With the depth of study many people will find a paragraph of code reuse the odds are very large, and if you write once, it is obvious that the efficiency will be relatively low, if there is a way to write before the same or the difference between the code is now to use the words can improve the efficiency of writing code, And if it goes wrong, it's clearer when it's corrected. At this point we will use what we are going to learn today: The function, which solves the requirement that we want to reuse a piece of code multiple times. Let's look at what the function is, what his definition is.

Function: A collection of lines of code that is written to perform certain functions. Can be called by the same program or other program.

A function is the basic constituent unit of C language.

The advantages of the function: the code is more concise, easy to maintain, can improve the reusability of code.

The popular point of understanding is that a paragraph in order to achieve a certain function of the small program packaged, packaged into a small package, and tagged, and then can be readily accessible.

When are functions used? Whenever you write a program, the repetitive need to implement some kind of function, it is best to use the function, a write of course can also be done, but as the previous said the efficiency is too low, there is a labor-saving method why not?

It's time for you to find out where to use it, and how to use it, and here's a list of examples of how and where to use it.

Functions are divided into built-in functions and custom functions, and the way to customize functions is to:

return value type function name (parameter)

{

function body;

return value;

}

Life case: Make Ham

Ham type [A1] make Ham [A2] (hog [A3])

{

Kill a pig;

Hair removal

Cleavers

Added starch;

Add seasoning;

.....

Packaging [A4] out ham; [A5]

}

[A1] Return value type: Can have a return value, or no return value is not used void (such as void Main), to return the value of the data type should be noted

[A2] Function name: a name for the function, similar to the name of a person (simply say that the function names, convenient later call)

[A3] Parameter: Raw material

[A4] Function body: Describes the function that the current function needs to complete (simply say what the current function does)

[A5] return value: The result of the function to the external output, the return value and function definition of the return type to the corresponding

Not to be continued ...

C Language Learning Sixth chapter

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.