Struct, C structure
Link: http://www.orlion.ga/758/
struct point { double x, y;};
In this way, the identifier point is defined. Since it is an identifier, its naming rules are the same as variables, but not a variable but a type. This identifier is a Tag in the C language, the entire struct point {double x, y;} can be considered as a type name, just like int or double, but this is a composite type. If you use this type name to define variables, you can write:
struct point { double x , y;} p1 , p2;
In this way, p1 and p2 are the variable names. ";" must be added after the variable definition, and ";" cannot be omitted after the struct definition (such as the first code.
Regardless of the method used to define the point Tag, you can directly use struct point to replace the type name. For example, you can re-define two variables as follows:
struct point p3 , p4;
If a variable is defined when the struct type is defined, you do not need to write a Tag. For example:
struct { double x , y;} p1 , p2;
Struct variables can be accessed using the "." OPERATOR:
# Include <stdio. h> int main (void) {struct point {double x, y;} p; double x = 1.0; p. x = x; z. y = 2.0; struct point p2; printf ("z x: % f, y: % f \ n", z. x, z. y); return 0 ;}
Struct can also be initialized during definition, for example:
struct point p = {1.0 , 2.0};
If the data in the brackets is less than that in the struct, the unspecified members are initialized with 0, just like the uninitialized global variables. Struct value assignment is somewhat different from the basic data type.ErrorOf:
struct point p;p = {1.0 , 2.0};
However, struct point p1 = {1.0, 2.0}; struct point p2 = p1; p1 = p2; this way.