c语言中函数的形参是数组的时候,传递的是地址

#include<iostream.h>

#include<stdio.h>

voidsort(double a[],int n);

int  main()

{

doublea[]={3,2,56,32,12,45,6};

sort(a,7);

cout<<endl;

for(inti=0;i<7;i++)

cout<<a[i]<<"";  

getchar();

return  0;

}

 

voidsort(double a[],int n){

inti=0,j=0;

doubletem=0;

while(i<n)

{

for(j=0;j<n-i-1;j++)

{

if(a[j]<=a[j+1])

{tem=a[j];a[j]=a[j+1];a[j+1]=tem;}

 

 

 

 

 

}

cout<<a[n-i-1]<<" ";

i++;

}

 

cout<<endl;   

for(i=0;i<n;i++)

cout<<a[i]<<"";  

}

 2 3 6 12 32 45 56

56 45 32 12 6 3 2

56 45 32 12 6 3 2

posted on 2011-05-28 17:52  xuq  阅读(422)  评论(0编辑  收藏  举报

导航