Simple data structures
suggest changeA structure packages related data so that it can be handled as one object.
Declaring a simple struct that holds two int members:
struct point
{
int x;
int y;
};
x and y are the members (also called fields) of struct point.
Defining and using structs:
struct point p; // declare p as a point struct
p.x = 5; // assign members of p
p.y = 3;
Structs can be initialized at definition. The above is equivalent to:
struct point p = {5, 3};
Structs may also be initialized with designated initializers.
Members are also read with the . operator:
printf("point is (x = %d, y = %d)", p.x, p.y);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents