私はポインタに全く新しいです、私はこれについてお詫びします、私はポインタの配列を渡し、その配列のモードを取得するはずです。配列がポインタのセットとして渡された後、配列を操作してモードを見つけることができません。試してみると構文エラーが発生します。配列のポインタを関数に渡して、配列のモードを見つけるにはどうすればよいですか? C++
EDIT:リストをポインタの配列に変更したため、ランタイムエラーが発生します。
int main()
{
int size=0;
int *list[size];
cout<<"Please enter the size of your array: ";
cin>>size;
cout<<"\nPlease enter the numbers in your list seperated by spaces: ";
for(int i=0;i<size;i++)
{
cin>>*list[i];
}
cout<<endl;
int mode=getMode(list,size);
cout<<"\n"<<mode<<endl;
return 0;
}
int getMode (int* list[], int arraySize)
{
cout<<"The array you entered is listed below\n "<<list[0];
for(int i=0;i<arraySize;i++)
{cout<<setw(3)<<list[i];}
int *number=list[0];
int count1=0;
int count2=0;
int mode=0;
for(int j=1;j<arraySize;j++)
{
for(int i=1;i<arraySize;i++)
{
if(list[i]==number)
{
count1++; //counts the number of instances that the number occurs
}
}
if(count1>count2)
{
mode= *list[j];
count2=count1;
}
count1=0;
}
return mode;
}
'list'は、整数の配列ではなく、ポインタの配列です。 – Barmar
配列を関数に渡すと、自動的にポインタに減衰します。 '&list'を使う必要はありません。 – Barmar
私はリストをintの通常の配列にして、参照タグなしでそれを渡そうとすると、コンソールはint型をint型に変換できないことを私に伝えます**。 –