什麼是函式?
函式說明
6/5- #include<iostream>
- #include<cstdlib>
- using namespace std;
- //自訂函式
- void hello()//void 沒有回傳值 沒有return
- {
- cout<<"hello!"<<endl;
- }
- int main()
- {
- hello();
- system("pause");
- return 0;
- }
複製代碼 自訂函式:
1. hello()
2. myPlus(int x,int y,int z)- #include<iostream>
- #include<cstdlib>
- using namespace std;
- void hello()
- {
- cout<<"HELLO!!"<<endl;
- }
- int myPlus(int x,int y,int z)
- {
- return x+y+z;
- }
- int main()
- {
- hello();
- cout<<myPlus(2,5,1)<<endl;
- system("pause");
- return 0;
- }
複製代碼- #include<iostream>
- #include<cstdlib>
- using namespace std;
- void hello();
- int myPlus(int,int,int);
- int main()
- {
- hello();
- cout<<myPlus(2,5,1)<<endl;
- system("pause");
- return 0;
- }
- void hello()
- {
- cout<<"HELLO!!"<<endl;
- }
- int myPlus(int x,int y,int z)
- {
- return x+y+z;
- }
複製代碼 |