[圖解C] Example 908: there are some data with the same structure

// Example 908: there are some data with the same structure
#include <stdio.h>
#include <stdlib.h>

int main()
{
    struct student
    {
        char name[10];
        int math;
        int english;
    };
   
    // declare an array with the same structure
    struct student classA[3] =
    {{"Jay", 87, 69}, {"Jolin", 77, 88}, {"Henrry", 78, 70}};
   
    int i;
    float aveMath=0, aveEng=0;
   
    // print by using array
    for (i=0 ; i<3 ; i++){
        printf("%s \t math= %d \t english= %d \n",
        classA[i].name, classA[i].math, classA[i].english);
       
        aveMath += classA[i].math;
        aveEng += classA[i].english;
    }
   
    printf("============================\n");
   
    // print by using pointer
    for (i=0 ; i<3 ; i++){
        printf("%s \t math= %d \t english= %d \n",
        (classA+i)->name, (classA+i)->math, (classA+i)->english);
    }
   
    system("pause");
    return 0;
}