Access to C ++ array to access structure

I study C ++ from Schildt’s book and don’t quite understand what he means by the third structure; Can someone explain this →

To access a specific structure within an array of structures, you must index the name of the structure. For example, to display the on_hand element of the third structure, you would write cout <invtry [2] .on_hand;

Some codes:

struct type{
 char item[40];
 double cost;
 double retail;
 int on_hand;
 int lead_time;
}invtry[SIZE];
+5
source share
3 answers

The third structure in the array of structures is the one that is placed in the third position in the array, i.e. with index 2.

() invtry ( SIZE) type. , invtry[0] - , invtry[1] , invtry[2] - , , SIZE >= 3.


:

struct type{
 char item[40];
 double cost;
 double retail;
 int on_hand;
 int lead_time;
};

const int SIZE = 500;

type invtry[SIZE];

, , SIZE, . : , type ( !) - , type. type, invtry.

, , - .

500 . "type" "Product", , 500 . , , ..

, invtry[2]. on_hand, invtry[2].on_hand. on_hand .

lead_time , , lead_time: invtry[2].lead_time.

, ( ), 500 - . .

+5

" " "".

, 3- invtry ( ), invtry [2] (2 3, 0), -, ...

. invtry [2].on_hand , 'on_hand' 'invtry'

+1

. . . C-isms . . ACCU .

" ++" Koenig Moo " ++" Stroustrup .

0
source

All Articles