C语言error C2664: 'Bubblesort' : cannot convert parameter 1 from 'int *' to 'int *[]'
#include<stdio.h>intmain(){voidBubblesort(int*a[]);inta[5]={5,6,4,7,2};inti;Bubblesor...
# include <stdio.h>
int main()
{
void Bubblesort(int * a[]);
int a[5] = {5,6,4,7,2};
int i;
Bubblesort(a);
for (i=0; i<5; i++)
{
printf("%d ",a[i]);
}
printf("\n");
return 0;
}
void Bubblesort(int *a[])
{
int i, j;
int * temp;
int flag = 1;
for (i=1; i<5 && flag; i++)
{
flag = 0;
for ( j=5-1; j>=i; j-- )
{
if (a[j] > a[j-1])
{
temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
flag = 1;
}
}
}
}
运行后出现error C2664: 'Bubblesort' : cannot convert parameter 1 from 'int *' to 'int *[]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 展开
int main()
{
void Bubblesort(int * a[]);
int a[5] = {5,6,4,7,2};
int i;
Bubblesort(a);
for (i=0; i<5; i++)
{
printf("%d ",a[i]);
}
printf("\n");
return 0;
}
void Bubblesort(int *a[])
{
int i, j;
int * temp;
int flag = 1;
for (i=1; i<5 && flag; i++)
{
flag = 0;
for ( j=5-1; j>=i; j-- )
{
if (a[j] > a[j-1])
{
temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
flag = 1;
}
}
}
}
运行后出现error C2664: 'Bubblesort' : cannot convert parameter 1 from 'int *' to 'int *[]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 展开
1个回答
展开全部
void Bubblesort(int *a[]) //参数是一个指针数组
Bubblesort(a);//调用参数是一个数组(指针)
//将void Bubblesort(int *a[]) 改为 void Bubblesort(int a[]) 或者 void Bubblesort(int *a)
// int * temp;改为 int temp;
完整代码如下
# include <stdio.h>
int main()
{
void Bubblesort(int *a );
int a[5] = {5,6,4,7,2};
int i;
Bubblesort(a);
for (i=0; i<5; i++)
{
printf("%d ",a[i]);
}
printf("\n");
return 0;
}
void Bubblesort(int *a)
{
int i, j;
int temp;
int flag = 1;
for (i=1; i<5 && flag; i++)
{
flag = 0;
for ( j=5-1; j>=i; j-- )
{
if (a[j] > a[j-1])
{
temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
flag = 1;
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询