Search⌘ K

Definition of Structs

Explore the definition of structs in the D programming language and understand how they allow you to create new types by combining related variables. Learn to use structs to simplify function parameters, return multiple values, and organize complex data effectively in your programs.

Chapter overview

Fundamental types are not suitable to represent higher-level concepts. For example, although a value of type int is suitable to represent the hour of the day, two int variables would be more suitable together to represent a point in time: one for the hour and the other for the minute.

Structs are the features that allow defining new types by combining already existing types. The new type is defined by the struct keyword. By this definition, structs are user-defined types. Most of the content of this chapter is directly applicable to classes as well, especially the concept of combining existing types to define a new type.

This chapter covers only the basic features of structs. You will see more of structs in the following lessons: