我需要创建一个人的数组,同时使用这样的结构: -
typedef struct Person
{
int age; //needs to be randomly generated
int height; //needs to be randomly generated
int weight; //needs to be randomly generated
} Person;
但我不知道如何使用如下数组执行此操作: -
人[0]
人[1]
人[2]
任何提示都会很棒!!
答案 0 :(得分:0)
typedef struct Person
{
int age; //needs to be randomly generated
int height; //needs to be randomly generated
int weight; //needs to be randomly generated
} Person;
// Create an array of 5 Persons
Person persons[5];
// Set the data of the first person.
person[0].age = 25;
person[0].height = 175; // in cm
person[0].weight = 68; // in kg