Function
1. What is a function and why do you use a function
function is a piece of code that will function as a modular
Stability can be reused
2. How functions are defined
Two ways to define it: 1. Declare after declaration (the implementation part of the function is longer)
2. Declaration and implementation put together (logic simple note: Must be placed in front of the main function)
The reason is that the execution of the program follows from top to bottom
Function naming rules: first letter lowercase
The format of the function (the void type does not require a return value)
return value type name ( parameter, parameter, parameter ) {
function Body
Code
Return
}
int add (int a, int b) {
int result = a + B;
return result;
}
void print (int a) {
printf ("%d\n", a);
}
3. Invocation of functions
int result = Add (10, 20);
print (result);
The style of ps://programming
Try not to see the actual implementation in the main function, only the logical result
December 7 function function