#include <stdio.h>
#include <string.h>
typedef struct{
int age;
int year;
char* name;
} student ;
int main(int argc, char* argv[]){
student p[3];
p[0].name = "fred";
p[0].age = 21;
p[0].year = 2;
p[1].name = "barney";
p[1].age = 23;
p[1].year = 2;
p[2].name = "wilma";
p[2].age = 24;
p[2].year = 3;
printf("n%s: age: %d, year: %dn",p[0].name,p[0].age,p[0].year);
printf("n%s: age: %d, year: %dn",p[1].name,p[1].age,p[1].year);
printf("n%s: age: %d, year: %dn",p[2].name,p[2].age,p[2].year);
return 0;
}
If you compile and run this code, the output is as follows:
secondhalf-lm:junk clacy$ gcc structarray.c -o structarray && ./structarray
fred: age: 21, year: 2
barney: age: 23, year: 2
wilma: age: 24, year: 3
christo