What are the knowledge points of C language functions?
This article mainly introduces "what are the knowledge points of C language functions". In daily operation, I believe that many people have doubts about the knowledge points of C language functions. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions about "what are the knowledge points of C language functions?" Next, please follow the editor to study!
A preliminary study of the functions in the program
The concept of function
A function is a program part with a specific function (can be used as a black box)
Function has a clear way to use (fixed input corresponds to fixed output)
A function is reusable in a program (a tool in a program).
Type of function
Data processing (data → data)
Process x into y by some rule, such as: y = 2x + 1
Process definition (data → function)
Perform a series of actions (based on data) to perform a function, such as screen printing
The components of functions in C language
Function name: unique identification of the function
Function parameter definition: data input (data → data, data → action)
Function return type:
Data output (data → data)
No return value (data → action)
Examples of generalized functions:
Returns the type function name (parameter 1, parameter 2)
{
Program statement 1
Program statement 2
.
Program statement n
}
Examples of functions in C language
Function call
Call a defined function through the function name
When a function is called, you need to specify the specific values of the function parameters in turn.
The result (return value) of a function call can be saved in a variable of the same type.
Let's take a look at the code for a function call:
# include int func_demo (int x) {int y = 0; y = 2 * x-1; return y;} int main () {int R1 = func_demo (1); int R2 = func_demo (5); int R3 = func_demo (10); printf ("R1 =% d\ n", R1); printf ("R2 =% d\ n", R2); printf ("R3 =% d\ n", R3); return 0;}
The following is the output:
Let's take a look at another piece of code that writes a function to calculate the sum:
# include int sum (int n) {int r = 0; int I = 0; for (iTun1; I