C编程指针函数问题
#include<stdio.h>int findmax(int *p,int m,int n,int *prow,int *pcol);
void main()
{
int *pscore,i,j,m,n,maxscore,row,col;
printf("please enter array size m,n:");
scanf("%d,%d",&m,&n);
pscore=(int *) calloc(m*n,sizeof(int));
if(pscore==NULL)
{
printf("no enough memory!\n");
exit(0);
}
printf("please enter the score:\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d\n",&pscore[i*n+j]);
maxscore=findmax(pscore,3,4,&row,&col);
printf("maxscore=%d,class=%d,number=%d",maxscore,row+1,col+1);
free(pscore);
}
int findmax(int *p,int m,int n,int *prow,int *pcol)
{
int i,j,max;
max=p[0];
*prow=0;
*pcol=0;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(p[i*n+j]>max)
{
max=p[i*n+j];
*prow=i;
*pcol=j;
}
return(max);
}这个pscore=(int *) calloc(m*n,sizeof(int));
if(pscore==NULL)申请字节空间。最后free(pscore);。这有什么用,申请了又放出来,不用这个不是写的更简洁吗,有这个对个程序有什么用。不解