私はちょうどコードを始めるばかりで、今は配列について学んでいます。私は配列のリストを取るプログラムを書こうとしていて、最初か最後の数字が2かどうかを教えてくれます。これを行うには、関数を使用しています。私が間違っているのは何g ++コンパイラが私の関数を認識していません
#include <iostream>
using namespace std;
const int size = 6;
bool firstlast(int array[size]);
int main()
{
int array[size];
for (int index = 0; index < size; index++)
{
cout << "Enter value for array[" << index << "]\n";
cin >> array[index];
}
bool check = firstlast(array[size]);
if (check)
cout << "The array either starts or ends in 2!\n";
else
cout << "The array does not start or end with 2.\n";
return 0;
}
bool firstlast(int array[size])
{
if (array[0] == 2)
return true;
if (array[size - 1] == 2)
return true;
return false;
}
:
私のコードは次のようになりますか?
candidate function not viable: no known conversion from 'int' to 'int *' for 1st argument; take the address of the argument with and
エラーは何ですか? – Ryan
私はちょうど質問 –
にそれを追加しました。宣言は 'bool firstlast(int array [size]);'でなければなりません - 関数の定義と一貫性を持ち、配列の型を指定する必要があります。 –