|
3鱼币
- #include <stdio.h>
- //返回指针的函数
- //类型名 *函数名(参数表列);
- //例如: int *a(int x,int y);
- void main()
- {
- double score[][4] = {{60.0, 70.0, 80.5, 90.5}, {56.0, 89.0, 67.0, 88.0}, {34.2, 78.5, 90.5, 66.0}};
- double *search(double (*pointer)[4], int n);
- double *p;
- int i, m;
- printf("Please enter the number of student: ");
- scanf("%d", &m);
- printf("The scores of No.%d are: \n", m);
- p = search(score, m);
- for( i=0; i < 4; i++)
- {
- printf("%5.2f\t", *(p + i));
- }
- printf("\n\n\n");
- }
- double *search(double (*pointer)[4], int n)
- {
- double *pt;
- pt = *(pointer + n);
- return pt;
- }
复制代码 为什么是pt = *(pointer + n); 而不是pt=pointer+n;
*不是取值吗?这里应该不是返回一个地址吗?为什么要取值
|
最佳答案
查看完整内容
double *search(double (*pointer)[4], int n)
{
double *pt;
pt = *(pointer + n);
pointer是一个二维数组的首地址,它指向每一个一维数组[4]类型的首地址,*pointer得到的就是每个移位数组的首地址。
也就是说 pointer 是一个指针的集合,它里面存放的都是地址,你取它的内容,也就自然取出的是地址了呀。
不知道这样说你明白吗。
实在不明白就下断点调试一下。看一看pointer在栈中的值。
|