C++ Arrays of Structure access -
I am studying C ++ from Schildt's book and it does not quite understand that it is the third structure What is the meaning below; Can someone explain this ->
To use a specific structure within an array of structures, you should be an indicator of the structure name. For example, to display an on-house member of the third frame, you might see cout & lt; & Lt; Invtry [2] .on_hand;
Some code:
structure type {four items [40]; Double cost; Dual retail; Int on_hand; Int lead_time; } Invitry [SIZE]; The third composition in an array of structures is placed at third place in third place.
array, that is, an indicator 2 one.
In your (ugly) code, invtry
is declared as array (size SIZE
). type of structures
. Therefore invtry [0]
is the first element, invtry [1]
second, and invtry [2]
third - assuming, of course, SIZE and gt; = 3
.
Normally, you will write:
structure type {four items [40]; Double cost; Dual retail; Int on_hand; Int lead_time; }; Int int SIZE = 500; Invitry type [SIZE]; Except for the definition of
, there is a synonym for what you have written but it leads to less delusion - in one part you say that A type
(awesome name for the structure) - In other words, you define the type
type later, you type a type of type type type
, which is called invtry
.
It is in the same line, as the author, just terrible - in my eyes
Now you have an array of 500 strings. If "Type" was a "product," then you have an array representing 500 products. With each item, cost, retail etc.
To use the third structure in the array, type invtry [2]
. To access your specific on_hand
field, type invtry [2] .on_hand
. It has nothing to do with the specific status of the defined type of layout in on_hand
.
If you want the lead_time of the third structure, then first use the third structure and then its lead_time
member: invtry [2] .lead_time
.
Definitely there is a default (paramagnetic) manufacturer of type, 500 products are Uninitialized - you have trash in them but this is your problem.
Comments
Post a Comment