Home  >  Q&A  >  body text

c++ - int类型的实参和int*类型的形参不兼容

#include<iostream>
using namespace std;
int ar[20];
int main()
{
    cout << "Please input 20 number to ar.";
    for (int i = 0; i < 20; ++i)
    {
        cin >> ar[i];
    }
    cout << "The maximum number is:" << Max(ar[20]);

    return 0;
}
//Function for Maximum.
int Max(int arr[20])
{
    int max = arr[0];
    for (int j = 1; j < 20; ++j)
    {
        if (arr[j] > max)
            max = arr[j];
    }
    return max;
}
阿神阿神2764 days ago1521

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-17 13:09:02

    The Max function call is wrong, Max(ar), not Max(ar[20])

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 13:09:02

    int Max(int arr[])

    cout << "The maximum number is:" << Max(ar);

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:09:02

    Okay, I've found the error.

    reply
    0
  • Cancelreply