并不是不规范的问题,你子程序写法只能在子程序中输出正确的数据,而在主函数中无法得到交换过的x和y的值。参考程序运用指针让子程序去读写a和b的值,在子程序执行完成后,a和b的值确实得到了交换。
你的程序中子程序采用的不是指针类型参数,这样子程序无法将交换过后的值传回来。
#include<stdio.h>int *d_bubblesort(int a[],int n)//数组长度为n的冒泡降序排序
{
int i,j
int temp
for(i=0i<ni++)
{
for(j=n-1j>ij--)
{
if(a[j]>a[j-1])
{
temp=a[j-1]
a[j-1]=a[j]
a[j]=temp
}
}
}
return a
}
void main()
{
int i
int *p=NULL
int a[10]={6,5,4,1,2,3,9,8,7,10}
int *(*fun)(int*,int)
fun=d_bubblesort
p=fun(a,10)
for(i=0i<10i++)
{
printf("%d\t",p[i])
}
}