using namespace std;
The class Student
{
Public:
Student (int, int);
Void Max (Student * s);
Private:
int num;
Int scor.
};
Student: : Student (int int n, s) : num (n), scor (s) {}
Void Student: Max (Student * s)
{
Int I, max_num=0, max_scor=0;
for(i=0; i<5; + + I)
If ((s + I) - & gt; Scor & gt; Max_scor)
{
Max_scor=(s + I) - & gt; Scor.
Max_num=(s + I) - & gt; Num.
}
Cout<& lt;" Achievement of the highest student id as "& lt;
Int main ()
{
Student s [5]=
{
Student (1, 78),
Student (2, 92),
Student (4, 81),
Student (4, 89),
Student (5, 68)
};
Student * p;
P=& amp; S [0]. Why does the pointer p is given by the address of s0
P - & gt; Max (p);//Max is the method of class
return 0;
}
CodePudding user response:
P==& amp; S [0]==s + 0==s pointing to the first elementS + I==& amp; S [I] to the I + 1
(s + I) - & gt; Scor the I + 1 student achievement
Reference:
Tan Haoqiang part "C programming" pointer
"Deep understanding of the C pointer"