指针作为函数参数(处理数组的四种方式)

//数组名传递给指针子参数  
#include 
#define N 3
float average(float * g); 
int main()
{
	float grade[N]={60,75,80};	
	printf("学生的平均成绩是:%.3f\n",average(grade)); 
	
}
float average(float * g)
{
	float *a=g; //这句话很重要 
	float ave,sum=0;  
	for(;g

-------------------------------------------------------------------------------------------------------------------------------------------------------

//数组名传递给数组名
#include 
#define N 3
float average(float grade[N]); 
int main()
{
	float grade[N]={60,75,80};	
	printf("学生的平均成绩是:%.3f\n",average(grade)); 
	
}
float average(float grade[N])
{
	int i; //
	float ave,sum=0;  
	for(i=0;i

-------------------------------------------------------------------------------------------------------------------------------------------------------

//指针传递给数组名
#include 
#define N 3
float average(float grade[N]); 
int main()
{
	float grade[N]={60,75,80};	
	float * a=grade; 
	printf("学生的平均成绩是:%.3f\n",average(a)); 
	
}
float average(float grade[N])
{
	int i; //
	float ave,sum=0;  
	for(i=0;i

-------------------------------------------------------------------------------------------------------------------------------------------------------

//指针传递给指针子参数  
#include 
#define N 3
float average(float * g); 
int main()
{
	float grade[N]={60,75,80};	
	float * a=grade; 
	printf("学生的平均成绩是:%.3f\n",average(a)); 
	
}
float average(float * g)
{
	float *a=g; //
	float ave,sum=0;  
	for(;g

//指针传递给指针子参数  
#include
#define N 3
float average(float * g); 
int main()
{
float grade[N]={60,75,80};
float * a=grade; 
printf("学生的平均成绩是:%.3f\n",average(a)); 

}
float average(float * g)
{
float *a=g; //这句话很重要 
float ave,sum=0;  
for(;g sum+=*g;
return ave=sum/N;

}


你可能感兴趣的:(C语言杂记)