【发布时间】:2017-03-29 21:48:24
【问题描述】:
我为一个对数组进行排序的函数编写了代码,然后我可以在主文件中访问它。
我面临的问题是我无法理解如何传递数组和对数组进行排序。
函数的初始化。
void sort (int *ary[], int len);
主要功能
int main ()
{
int max [4]= {2,8,5,9};
sort(&max, 4);
for (int l =0; l<4;l++)
{
cout<< max[l]<< " "<< endl;
}
system("pause");
return 0;
}
通过冒泡排序对数组进行排序的函数。
void sort (int *ary[], int len )
{
int temp=0;
for (int i = 0; i<len; i ++)
{
for (int j= 0 ; j<len ;j++)
{
if (ary[j]> ary[j+1])
{
temp = ary[j];
ary[j] = ary[j+1];
ary[j+1]= temp;
}
}
}
}
我收到以下错误消息:
visual studio 2012\projects\problem2\problem2\pract.cpp(11):错误 C2664: 'sort' : 无法将参数 1 从 'int [4]' 转换为 'int *[]'
如何解决此错误?
【问题讨论】:
标签: pointers visual-studio-2012 reference