...

/

Introduction to Structs

Introduction to Structs

This lesson gets you acquainted with the basics of Structs.

What Are Structs?

Structs consist of related items that potentially have different data types.

Structs are similar to tuples in this regard. However, unlike tuples, you must define the data type of the item within the struct.

Structs help to create custom data types.

Let’s consider a real life example. You know that a rectangle has two measurements, width and height. Suppose you have several rectangles which you can name. Once you have declared a rectangle items within the struct, you can initialize the values according to the type of rectangle. Suppose the dimensions of a rectangle may vary according to the color of the rectangle.

svg viewer

Declare a Struct

Structs are declared using a ...