Home > Back-end >  Address operator
Address operator

Time:12-17

# include//for m class, each class n in a maximum score
# include
Int MAX (int * h, int * l, maxscore int * and an int m, int n);//used to reach the maximum value and position
Int main (void)
{
Int * score;//each student's score
Int I, j, m, n;
Int h, l;//used to record the maximum line
Int the biggest;
Printf (" do enter the num of the classes and the students \ n ");
The scanf (" % d % d ", & amp; M, & amp; n);
Score=(int *) calloc (m * n, sizeof (int));
If (score==NULL)
{
Printf (" No memory \ n ");
exit(0);
}
Printf (" do enter the score \ n ");.
for(j=0; J{
for(i=0; i{
The scanf (" % d ", & amp; Score/j * n + I);
}
}
The biggest=MAX (& amp; H, & amp; L, score, m, n);//get the maximum value and position
Printf (" class=maxscore=% d, % d, number=% d \ n ", the biggest, h + 1, m + 1);
Free (score);
return 0;
}
Int MAX (int * h, int * l, maxscore int * and an int m, int n)
{
Int I, j, Max.
Max=maxscore [0].
* h=0;
* l=0;
for(j=0; J{
for(i=0; i{
If (maxscore [j * m + I] & gt; Max)
{
Max=maxscore [j * m + I];
* h=j;
* l=I;
}
}
}
return max;

}
Why don't the score in parentheses line 26 the function on the address operator

CodePudding user response:

Score=(int *) calloc (m * n, sizeof (int));//the value of the score is the memory address for application here, & amp; Score is the score variable own address, and the two address is different, and & amp; Score is a secondary pointer * *, and MAX parameter type does not match the
MAX processing, is offered in order to traverse the memory address, rather than to traverse the score variable own address & amp; Score (because the score variable own address nothing, only the memory address above apply for necessary information), so it is ok to pass score

The following can understand?
int a;//a is type int, & amp; A what kind? Is type int *
Similarly
Int * a;//a is type int *, & amp; A what kind? Type is int * *

So
Int a []={1, 2, 3};
Int * p=a;
//p value is the address of a, & amp; P is p own address () is a secondary pointer, traverse & amp; P is not get 1, 2, 3, only through a (that is, the value of the p) will be 1, 2, 3

So the MAX to score rather than & amp; score

CodePudding user response:

Because the score is a pointer, a pointer, and parameter types match, can have a look at the score is malloc application space
  • Related