C + + function one, function introduction
A function is a method, which is a piece of code to implement a specific function
Second, function structure
return value type function name (parameter list) {
function body
}
Sum function
int sum (int a,int b) {
return a+b;
}
Forget function structure How to write, think of the main function structure, the main function will always write it
int main ()
{
}
The int description has a return value, the main description has the function name, the parentheses () description has the argument list, the curly brace {} Indicates the function body
Third, the Code
1 /*2 Function3 simple usage of functions4 */ 5#include <iostream>6 using namespacestd;7 8 //function Declaration9 intSumintAintb); Ten //Sum function One intSumintAintb) { A returnA +b; - } - the intMain () - { - intans; - //function Call +Ans=sum (3,5); -printf"%d\n", ans); + return 0; A}
Iv. Results
8
C + + functions