A struct (data structure) is a group of related variables. These variables, refered to as members, can have different types and different lengths.
Struct members can contain pretty much any type of data. The only thing that you cannot have is a struct that contains a member of it's own type. This video will explain why.
There is another common way to create instances of your struct-type, but often this leads to having global variables. This video explains why globals are not good programming practice.
Review Questions
The following are examples of questions similar to what you can expect to see on the next exam.
- How many members can a struct have? As many as you want.
- Can a struct contain another struct as a member? Yes, as long as theres no cyclical dependence.