Defines an object array containing five student information (school, grades), define a pointer to the first element of the array, the first output 1,3,5 student information.
using namespace std;
class Student
{
public:
Student(int a,int b)
{
num=a;
grade=b;
}
void display()
{
cout<<num<<" "<<grade<<endl;
}
int num,grade;
};
int main()
{
Student a[5]
{
Student(1,100),
Student(2,99),
Student(3,98),
Student(4,97),
Student(5,10),
};
///定义指针输出1,3,5号学生的信息。
Student *pt=a;
pt->display();
pt=pt+2;
pt->display();
pt=pt+2;
pt->display();
return 0;
}