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