A struct is a conglomeration of other types. In c++ this structure becomes a new type itself. For instance a structure that defines fractional numbers may look like this...
Code:
struct Fraction
{
int denominator;
int numerator;
};
Now we have a type called Fraction that holds 2 int members. These members can be accessed by the dot operator . or with the arrow operator -> if you have a pointer to a Fraction instead.
Code:
Fraction fraction;
fraction.numerator = 1;
fraction.denominator = 2; // fraction now represents a half
Fraction* pfraction = &fraction;
pfraction->denominator = 4; // use a pointer to change fraction to a quarter
All real applications use structures in one way or another. The common struct is more important in c than c++ because c++ offers the class keyword. In c++ the only thing you have to remember about structs is that their default access specifier is public whereas class default access specifier is private. i.e
Code:
struct A
{
int x; // this is public
};
class B
{
int x; // this is private
};
struct C : A // Yes we can inherit structs. this is public inheritance
{
int y;
};
class D : B // this is private inheritance
{
int y;
};