structure help

• 01-10-2003
tetra
structure help
hi im really new to structures and i just wanted to know any real programming applications to them, like any use for them :)

any examples would help as well

thanks.
• 01-10-2003
Stoned_Coder
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; };```