Nested structure example

When nesting structures, the compiler needs to recognize the struct type you intend to use as a member. In the labs, first the inner struct will be defined, followed by defining the outer struct that contains the previously defined struct. This principle is also followed in the examples below. Alternatively, a forward declaration can be provided or the structs can be written physically nested already in the definition. You can look up those examples on your own if interested.

There are are total of three examples provided

  1. Using assignments to initialize the data in the structures (similarity to what you would do when prompting from the user).
  2. Using explicit initializing for the structure.
  3. Using compound literal to initialize the structure (supports re-initializing later in the code).
Example 1: AssignmentsExample 2: InitializingExample 3: Compound literal