#include<iostream>
using namespace std;
class Student
{public:
Student(int n,float s):num(n),score(s){}
void display();
private:
int num;
float score;
};
void Student::display()
{cout<<num<<" "<<score<<endl;};
int main()
{
Student stud[5]={Student(1002,78),Student(1004,89),Student(1005,78),
Student(1007,85),Student(1008,90)};
Student *p=stud;
for(int i=0;i<=2;p=p+2,i++)//p=p+2这个我有少少不明白,前面是i=0;i<2是指向的范围,p=p+2是指向是对象,但是如果p为0时(0+2=2),p为1时(1+2=3),p为2时(2+2=4),这样就不是指向1、3、5的学生了,大家帮忙一下。
p->display();
return 0;
}
i=0,p指向stud[0],i=1,p指向stud[2],i=2,p指向stud[4],但是你都需要一个条件吧,如果按你这样说,p=p+2这个条件都不需要用到了,直接删掉。
本回答被网友采纳