[疑问]二维数组a[][], a和*a的区别
void file2 (char (*pcourse)[10], int *pnum, float *pscore, float *paver);void good (char course[5][10], int num[10], float score[4][5], float aver[4]);
file2(course, num, *score, aver); 这里是用*score传的[0][0]首地址
good(course, num, score, aver); 这里用的0行首地址
为啥good函数用*score传地址会被警告,两者值都一样。
*a==*(a+0)==&a[0][0] &a[0]==a; 用编译器调试,他们是不是是这样等价的?请详解下。谢谢!!!
#include<stdio.h>
int main()
{
void input (int *pnum, float *pscore, float *paver, char (*pcourse)[10]);
void avsco (float *pscore, float *paver);
void avcou (char (*pcourse)[10],float *pscore);
void file2 (char (*pcourse)[10], int *pnum, float *pscore, float *paver);
void good (char course[5][10], int num[10], float score[4][5], float aver[4]);
int num[4];
float score[4][5], aver[4];
char course[5][10];
input(num, score[0], aver, course);
avsco(*score, aver);
avcou(course, *score);
file2(course, num, *score, aver);
good(course, num, score, aver);
}
void input (int *pnum, float *pscore, float *paver, char (*pcourse)[10] )
{
int i, j;
printf("please five courses!\n");
for (i = 0; i < 5; i++)
scanf("%s", (pcourse + i));
printf("plese input NO. and score!\n");
for (i = 0; i < 4; i++)
{
scanf("%d", pnum + i);
for (j = 0; j < 5; j++)
scanf("%f", (pscore + i * 5 +j));
}
}
void avsco (float *pscore, float *paver)
{
int i, j;
float average, sum;
for (i = 0; i < 4; i++)
{
sum = 0.0;
for (j = 0; j < 5; j++)
{
sum += *(pscore + i * 5 +j);
}
average = sum / 5;
*(paver + i) = average;
}
}
void avcou (char (*pcourse)[10],float *pscore)
{
int i;
float sum=0.0, average;
for (i = 0; i < 4; i++)
{
sum += *(pscore + i * 5);
}
average = sum / 4;
printf("couese1:%s average:%7.4f\n", *pcourse, average);
}
void file2 (char (*pcourse)[10], int *pnum, float *pscore, float *paver)
{
int lable, i, j, k;
printf(" =======Student who is file in two courses======\n");
printf("NO.");
for (i = 0; i < 5; i++)
{
printf("%s ", *(pcourse + i));
}
printf("\n");
for (i =0 ; i < 4; i++)
{
lable = 0;
for( j = 0; j < 5; j++)
if (*(pscore + i * 5 + j) < 60.0)
++lable;
if(lable >= 2)
{
printf("%d ", *(pnum + i));
for (k = 0; k < 5; k++)
printf("%7.4f ", *(pscore + i * 5 +k));
printf("%7.4f\n", *(paver + i));
}
}
}
void good (char course[5][10], int num[10], float score[4][5], float aver[4])
{
int i, j , k, lable;
printf(" =======Student whose score is good=======\n");
printf("NO. ");
for (i = 0; i < 5; i ++)
printf("%s ", course[i]);
printf("\n");
for (i = 0; i < 4; i++)
{
lable = 0;
for(j = 0; j < 5; j++)
{
if(score[i][j]>85)
++lable;
}
if(lable==5||aver[i]>=90)
{
printf("%d ", num[i]);
for( k = 0; k < 5; k++)
printf("%7.4f ", score[i][k]);
printf("%7.4f\n", aver[i]);
}
}
}
[此贴子已经被作者于2017-4-1 13:34编辑过]