Page 104 - Programming Microcontrollers in C
P. 104
Structures 89
then
people[1].name
is the same as
++pp->name
A structure can have another structure as a member element. Consider
struct point
{
int x;
int y;
};
where point contains two integer elements, x and y. A circle can
now be defined by
struct circle
{
struct point center;
int radius;
};
In this case access to the members of center is by
circle.center.x
or
circle.center.y
Of course the radius is accessed by
circle.radius
Functions can take structures as arguments and they can return
structures. For example, the function make_point() that follows
returns a structure.
struct point make_point(int x, int y)
{
struct point hold;
hold.x=x;