using namespace std;double midd(int arr[10], int size);int main() { int ax[10] =" />

### 在传递数组时从'int'到'int *'[-fpermissive]的无效转换

4754 观看

3回复

14 作者的声誉

``````cout << midd (ax [10], asize) << endl;
``````

``````#include <iostream>

using namespace std;
double midd(int arr[10], int size);

int main() {
int ax[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int asize = 10;
cout << midd(ax[10], asize) << endl;
}

double midd(int arr[10], int size) {
int acount = 0;
int mid1;
int mid2;
int amid = size / 2;

double mid = 0.0;

while (acount < 10) {
if (acount == amid) {
mid1 = arr[acount];
}
else if (acount == (mid + 1)) {
mid2 = arr[acount];
}
++acount;
}
mid = (mid1 + mid2) / 2.0;
return mid;
}
``````

### 回应 (3)

0

88548 作者的声誉

``````double midd(int arr[10],int size);
``````

``````double midd(int *arr,int size);
``````

1

22 作者的声誉

• 替换`cout<< midd (ax[10], asize );``cout<< midd (ax, asize );`

-现在`int*`传递了ax（）的指针，因此`midd()`将接受它。

0

8459 作者的声誉

``````cout << midd(ax, asize) << endl;
``````

``````double midd(int arr[], int size) { ... }
``````

``````#include <iostream>
#include <array>
using namespace std;

double midd(array<int, 10> a) {
int mid = a.size() / 2;
return (a[mid] + a[mid + 1]) / 2.0;
}

int main() {
array<int, 10> ax = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
cout << midd(ax) << endl;
}
``````