Technique to creating this structure:
An alternative technique of creating this structure, that is not as efficient, includes using the dot operator to refer to fields in the structure. The name of structure variable is followed by dot, or a period, and then name of the field within that structure. The Assignment statements can be used to assign values to the fields.
>> package.item_no = 123;
>> package.cost = 19.99;
>> package.price = 39.95;
>> package.code = 'g';
By using the dot operator in the first assignment statement, the structure variable is generated with the field item_no. The later three assignment statements add more fields to the structure variable.
Adding a field to the structure later is accomplished as shown former, by using an assignment statement.
The whole structure variable can be assigned to the other. This would make sense, for illustration, if the two structures had some values in common. Here, for illustration, the values from one structure are copied into the other and then two fields are selectively changed.
>> newpack = package;
>> newpack.item_no = 111;
>> newpack.price = 34.95
newpack =
item_no: 111
cost: 19.9900
price: 34.9500
code: 'g'