[C Language] use functions, and C language use functions
Bytes ------------------------------------------------------------------------------------------
// Function prototype Declaration: The function header ends with a semicolon to form a function prototype. Purpose: 1. Return type 2. function name 2. Parameter type (random name)
Void sum (int begin, int end );
// Function Definition void sum (int begin, int end) {int I; int sum = 0; for (I = begin; I <= end; I ++) {sum + = I;} printf ("% d to % d and % d are % d", begin, end, sum );}
Sum (10, 15); # void sum (int begin, int end): function header. # Void: return type. If void exists, only return with no value or return is used.
# Sum: function name;
# Int begin: parameter, including (type name ).
# In curly brackets: function body.
# Call a function: the function name (parameter value). It is not called without parentheses. If a parameter exists, the correct quantity and order are required. The parameter values are used to initialize parameters in the function in sequence.
# Return Value: return is written as a return or return expression. Do not use multiple return statements for a single exit. The final return value of 0 in the main function indicates that the operation is correct.
Call the function:
If the function has parameters, the number and type passed during the call must be correct. If they do not match, the compiler will perform some conversions, which may not be what you want; the function only transmits values rather than variables.
Local variable:
Local variables are defined in blocks, separate blocks (curly braces), function blocks, or statement blocks (such as if ).
Variables defined outside the block still exist in the block. variables defined in the block do not exist outside the block.
If the variables in the block are output outside the block, no output value exists.
If the block defines a variable with the same name as the outside, it overwrites the outside.
Variables with the same name cannot be defined in a block.
Local variables are not initialized by default.
The parameter is initialized when it enters the function.
Define three different parameter methods for a function:
Void d (int x );
Void d ();
Void d (int );
Link: http://www.cnblogs.com/farwish/p/4202576.html
@ Blackeye poet <www. chenwei. ws>