Assign values to structure variables

后端 未结 3 507
感动是毒
感动是毒 2021-01-30 18:31

A structure type is defined as:

typedef struct student{
    int id;
    char* name;
    double score;
} Student;

I construct a variable of type

3条回答
  •  被撕碎了的回忆
    2021-01-30 18:57

    In C99 standard you can assign values using compound literals:

    Student s1;
    s1 = (Student){.id = id, .name = name, .score = score};
    

提交回复
热议问题