Notes on C functions: c Functions

Source: Internet
Author: User

Notes on C functions: c Functions

Basic concepts and functions of return values return1> void can omit return2> return3 can be used multiple times> Other statements cannot be followed by return 4. note the weak syntax of the function. If the return value type is not written, the default value is int. If the return value is written, you can call a function that has not been defined. The returned value is 0: normal Exit 1: Abnormal exit function Note: 1> nested Function Definition 2> infinite loop call, self-tuning 3> repeated definition and Declaration are not allowed

For a function whose return value is void, do not use return.

Void test1 ()
{
Return;
}

Void test1 () {} For the int type function int test2 ()
{
// The return value is of the int type, so the return value should be followed by an integer.
Return 0; // This 0 is just written at will. The specific value returned depends on the business logic.
// Return;
}

Void test2 (int n)
{
}

Int main ()
{
// Test2 receives int-type parameters, while test1 does not return values.
// Therefore, test1 () cannot be a parameter of test2.
Test2 (10 );
// Test2 (test1 ());
Return 0;
}
What should I pay attention to when defining C-language functions?

The first is the function name. It is best to let people know what this function is for at a Glance. At least don't misunderstand it.
Second, the number of parameters. The smaller the number, the better.
The third is annotations. This is not important to the writer, but to the reader.
The fourth is the function size. It is said that the function body cannot exceed 5 rows in strict cases. If it cannot be done, it can be shorter than a short point. If it is too long, it can be divided into several function writes.

Precautions for reusable functions in C Language

Read this article.
Function reusability and writing specifications
Blog.csdn.net/..6.aspx

Related Article

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.