函数常见方式
1.无参无返
void fun1(){
cout<< "This is fun1." << endl;
}
2.有参无返
void fun2(int num){
cout << "This is fun2." << endl;
cout << "num = " << num << endl;
}
3.无参有返
int fun3(){
cout << "This is fun3." << endl;
return 1;
}
4.有参有返
int fun4(int num){
cout << "This is fun4." << endl;
return num;
}
主函数调用
int main(){
fun1();
fun2(5);
int result3 = fun3();
cout << "result3 = " << result3 << endl;
int result4 = fun4(55);
cout << "result4 = " << result4 << endl;
}
结果
This is fun1.
This is fun2.
num = 5
This is fun3.
result3 = 1
This is fun4.
result4 = 55