Department of Engineering

IT Services

Structures

Structures are used to construct variables with multiple components of possibly differing types. Each component (also known as a data member or field) is referenced by a name rather than by an index expression as in arrays. A '.' is used to indicate data member access. Examples of definition and use:

struct Complex {
   float    re;
   float    im;
};

struct Time {
   int      hour;
   int      min;
};

Complex     a,b;
Time        t;

a.re = a.re + b.re;        // a = a + b
a.im = a.im + b.im;
t.hour = 12; t.min = 0;    // t = noon;