Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous
Next: Classes Up: C++ Summary Previous: Functions

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;
© Cambridge University Engineering Dept
Information provided by Tim Love
2006-12-08