C++中自定义函数的初级错误

 1 //自定义函数
 2 #include<iostream>
 3 using namespace std;
 4 int Area(w,h);//错误:参数要先定义再使用,所以c前要有c的类型。正确表述:Area(int w,int h)
 5 int main() {
 6     int a,b;
 7     cin >> a>> b;
 8     cout << Area(a,b) << endl;
 9 }
10 int Area(int w,int h) {
11     int w, h;//错误:形参重复定义,应当删除
12     int c = w * h;
13     return c;
14 }
15 //自定义函数时,括号中的变量要先定义,定义过之后,函数体中就不需要再次定义

猜你喜欢

转载自www.cnblogs.com/Shen-jiangqin/p/11519208.html
今日推荐