Chapter 8 - Structs
Exercise 1: Defined Types and Structs
Let’s create a struct type named
rectangle, that represents rectangular areas. It should have
width fields, both of type
Also create a
rectangleInfo function that accepts a
rectangle as a parameter.
rectangleInfo should print
"Length:" followed by the rectangle’s length, then
"Width:" followed by the rectangle’s width.
Finally, in your
main function, create a new
rectangle value, and set its
width fields. Then pass the
rectangleInfo to display its field values.
Length: 4.2 Width: 2.3