Structs

A composite data type made up of a finite collection of not necessarily homogenous elments classed members or fileds.

struct CartType
{
   int year;
   char make[10];
   char model[10];
   float price;
};

 

how to declare one

CarType  myCar;

how to use it

myCar.price = 20000.0;

legal use of structs

  • assignment to another struct variable of same type,
  • pass as a parameter to a function (either by value or by reference),
  • return as the value of a function.

 

See Figure 2.5 of book