1.无参无返
#include<iostream> using namespace std; void test1(){ cout<<"this is test01"<<endl; } int main(){ test1(); }
2.有参无返
#include<iostream> using namespace std; void test2(int a){ cout<<"this is test02="<<a<<endl; } int main(){ test2(100); }
3.无参有返
#include<iostream> using namespace std; int test3(){ //cout<<"this is test03"<<endl; return 1; } int main(){ int num1=test3(); cout<<"num1= "<<num1<<endl; system("pause"); }
4.有参有返
#include<iostream> using namespace std; int test4(int a){ //cout<<"this is test03"<<endl; return a+1; } int main(){ int num1=test4(5); cout<<"num1= "<<num1<<endl; system("pause"); }