I'm going to assume this is a "begginner" level question, and you don't actually really need to know what the compiler does to figure out which member of a struct
goes where or contains what.
If you image a struct
as one of those plastic things that hold a bunch of tools, each one perfect shape for one tool, so you have a "hammer" shaped space, another space for a "screwdriver", etc. In computer terms, each member of a struct
is a named "space" for a something.
An array of struct
is like a chest of drawers, where each drawer has a number, and in each drawer you have one of those plastic tool holders.
So, if we pick apart one of the statements in the code:
r [i].quotient = r [i].numer / r [i].denom;
The r
represents your entire set of "plastic tool holding things". [i]
selects one of them, and .quotient
picks the "quotient shaped hole". On the other side of the =
we have code that picks things out of the numer
and denom
shaped holes in the pastic tool holder.
The initialization is done in this line:
afile >> r [i].numer >> r [i].denom
it uses the >>
operator from afile
to read data into r
(our chest of drawer, where each drawer is a "plastic tool holding thing", selects the drawer number i
, and the numer
and denom
"holes".
(I personally prefer to write r[i].numer
, not using a space between the two, because in my head they belong together)