Structs
Struct Arrays
An array can store several struct values of the same type.
Struct Arrays
struct_arrays.c
#include <stdio.h>
struct Score {
int id;
int points;
};
int main(void) {
struct Score scores[3] = {{1, 10}, {2, 20}, {3, 30}};
int index = ;
int result = scores[index].points;
printf("points=%d\n", result);
return 0;
}
#include <stdio.h>
struct Score {
int id;
int points;
};
int main(void) {
struct Score scores[3] = {{1, 10}, {2, 20}, {3, 30}};
int index = ;
int result = scores[index].points;
printf("points=%d\n", result);
return 0;
}
#include <stdio.h>
struct Score {
int id;
int points;
};
int main(void) {
struct Score scores[3] = {{1, 10}, {2, 20}, {3, 30}};
int index = ;
int result = scores[index].points;
printf("points=%d\n", result);
return 0;
}
array of structs
`scores[index]` selects one struct value from the array.
field after index
Use `scores[index].points` to read a field from the selected element.