Before learning enum-type enum, it feels a little unaccustomed, where it is customary to understand that the understanding of the structure here is more convenient, because there are some similarities between the two.
Register a student's name and score with a struct, if it is less than 60 points, shows bad
#include <stdio.h>
typedef struct{
Char name[20];
float points;
Char *appraise; Here with a character pointer, if you use a normal string, the outside cannot be assigned a value
} students;
Define a struct, typeof the data label name, and define the structure as a students in TypeOf.
You can also define this
struct students{//With this definition, the variable declaration behind is a struct students, such as the lucky in main to be written as struct students Lucky
Char name[20]; If a typedef can be used to take a more convenient name, to refer to the struct students
float points;
Char *appraise;
};
Students Give_appraise (students *s) {//If the preceding typedef is not defined, the struct is used here students
if (s->points<60)
S->appraise= "Bad"; Here is passed in the *s pointer can be used s-> this arrow notation, if it is only passing s, you have to use s.appraise, but also to return out, although not as the array can not return, but this obviously no pointer operation convenient
Else
S->appraise= "Good"; This pointer operation can also be written out (*s). Appraise must be bracketed because the priority of the. is greater than *
}
int main (void) {
Students lucky = {"Lucky", 49, ""};
Give_appraise (&lucky); Address of the passing structure body
printf ("%s", lucky.appraise);
return 0;
}
C Language Learning Notes-structure