Concept
How can one structure be composed of another structure?
ComputerScienceOne / Declaration & Initialization
"typedef struct {\n\nint id;\n\nchar *firstName;\n\nchar *lastName;\n\ndouble gpa;\n\nDate dateOfBirth;\n\n} Student;\n\nCode Sample 23.1.: A Student structure declaration\n\ntypedef struct {\n\nint year;\n\nint month;\n\nint date;\n\n} Date;\n\nOnce we have defined a structure we can use it as we would a normal variable, so it makes sense that we could include it in another structure. This is a good illustration of a form of composition where one structure may be composed of other structures. Since the Student structure “owns” an instance of the Date structure, it is necessary to ensure that the Date structure is declared before the Student structure (just as we need to declare variables before we use them."
Related Ideas
- How can structures be dynamically allocated?ComputerScienceOne · Declaration & Initialization
- How do you dynamically allocate and initialize a structure?ComputerScienceOne · Selection Operators
- How do you declare and instantiate Java class instances?ComputerScienceOne · Usage
- How are structures defined and named in C?ComputerScienceOne · Alternative Declarations
- How should structure names and member variables be declared in C?ComputerScienceOne · Nested Structures