函数数组指针的一点疑问。解决办法
函数数组指针的一点疑问。
#include "stdio.h "
main()
{
float score[][4]={{60,70,80,90},{56,89,67,88},{34,78,90,66}};
float * search(float(* pointer)[4],int n);
float *p;
int i,m;
printf( "enter the number of student: ");
scanf( "%d ",&m);
printf( "the scores ofNo.%d are:\n ",m);
p=search(score,m);
for(i=0;i <4;i++)
printf( "%5.2f\t ",*(p+i)); /*22222*/
}
float *search(float (* pointer)[4],int n)
{
float *pt;
pt=*(pointer+n);/*11111*/
return(pt);
}
上面是一个关于打印出 数组中数据的程序
我的疑问是 11111这一点 *(pointer+n)是数组的第一维进行操作
但是22222 这里为什么同样是取了地址 *(p+i)却是 取指针地址+1的值呢????????
------解决方案--------------------
1111的pointer类型是 float[4] * 加1跳过4个float
222的p类型是float * 加1跳过1个float
------解决方案--------------------
float (* pointer)[4]就是实参score[][4]
pointer功能一样> > 没看懂
float *pt;
float **socre; //float score[][4];
这么写明白么~~~ ^_^
------解决方案--------------------
float (* pointer)[]
float *p
pointer是个数组名,p是个float指针
#include "stdio.h "
main()
{
float score[][4]={{60,70,80,90},{56,89,67,88},{34,78,90,66}};
float * search(float(* pointer)[4],int n);
float *p;
int i,m;
printf( "enter the number of student: ");
scanf( "%d ",&m);
printf( "the scores ofNo.%d are:\n ",m);
p=search(score,m);
for(i=0;i <4;i++)
printf( "%5.2f\t ",*(p+i)); /*22222*/
}
float *search(float (* pointer)[4],int n)
{
float *pt;
pt=*(pointer+n);/*11111*/
return(pt);
}
上面是一个关于打印出 数组中数据的程序
我的疑问是 11111这一点 *(pointer+n)是数组的第一维进行操作
但是22222 这里为什么同样是取了地址 *(p+i)却是 取指针地址+1的值呢????????
------解决方案--------------------
1111的pointer类型是 float[4] * 加1跳过4个float
222的p类型是float * 加1跳过1个float
------解决方案--------------------
float (* pointer)[4]就是实参score[][4]
pointer功能一样> > 没看懂
float *pt;
float **socre; //float score[][4];
这么写明白么~~~ ^_^
------解决方案--------------------
float (* pointer)[]
float *p
pointer是个数组名,p是个float指针