Struct Literals and Static Members

You’ll get to learn about struct literals and static members in this lesson.

Struct literals

Similar to being able to use integer literal values like 10 in expressions without needing to define a variable, struct objects can be used as literals as well.

Struct literals are constructed by the object construction syntax.

TimeOfDay(8, 30) // ← struct literal value

Let’s first rewrite the main() function using what we have learned. The variables will be constructed by the construction syntax and be immutable this time:

Get hands-on with 1000+ tech skills courses.