notexOPENOverview
Notex/Languages/Practice: Structs
01.32LESSON 32 OF 33 · 1 MIN READ

Practice: Structs

Always free to read

The following exercises test what you’ve learned about structs.

  1. Write a program that defines a struct called Employee with three fields: firstName, lastName, and id. The first two fields are of type string, and the last field (id) is of type int. Create three instances of this struct using whatever values you’d like. Initialize the first one using the struct literal style without names, the second using the struct literal style with names, and the third with a var declaration. Use dot notation to populate the fields in the third struct. Print out all three structs.

  2. Write a program that defines two different struct types that can be converted to each other.

  3. Write a program that defines two structs, Person and Pet. Pet has three fields, name, species, and age. The first two fields are of type string and the last is of type int. Person has two fields, name, and pet. The first is a string and the second is a Pet. Create an instance of Person and populate all fields. Print out the instance.

Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

Back to the library →
⌕
Search across the entire library ⌘ K