Data Structure basics-Use of struct and type alias typedef, structtypedef
I. Create struct
In C language, a common method to implement data structures is to use structure. The sample code is as follows:
Struct stu {int num; char ch ;};
Struct indicates to create a struct stu as the struct name, which contains various variable types (which can be nested with struct). The following is an example:
Struct stu s; scanf ("% d", & s. num); printf ("% d \ n", s. num );
The first line indicates the structure s in which the structure is created as stu. Then, the content in the access structure body needs to use the name. Name, for example, the s. num in the access structure s represents the num in the access structure s. For convenience, we will introduce the typedef keyword.
Ii. Usage of typedef
Typedef serves as an alias for the variable type. For example, long is too long. It is annoying to write long every time. We can simplify it like this.
Typedef long ll; ll B; scanf ("% lld", & B); printf ("% lld \ n", B );
So we can use struct as follows:
Typedef struct {int num; char ch;} stu; stu s; scanf ("% d", & s. num); printf ("% d \ n", s. num );
In this way, you can directly use stu to create a struct without using struct stu s; this is a long string.