166k views
2 votes
What are some reasons why you might want to create a "complex" or "compound" structure – an array of structures, a structure containing several arrays, even more complicated structures?

2 Answers

4 votes
This is because the difference between them is quite large so to show complete understanding of the topic you should answer the question
User Tim Hopper
by
6.1k points
6 votes

Answer:

When designing a program structure, sometimes we might want to encapsulate or group multiples attributes which are related to each other in a compound structure. This encapsulation offer a cleaner code structure and enable the code easier to be managed.

For example, we might want to program a student information system and we need a compound data structure that can be used to represent a group of related attributes associated with a student (e.g. student id, name, age, gender etc). We might create a compound data structure as follows

struct student {

int studentID;

string name;

int age;

string gender;

} ;

To effectively represent a group of students, we can create an array of student structure.

User RasmusWL
by
4.9k points