Introduction to structures (struct) in C++

Previously, we learned procedural/structured programming, where we only worked with primitive data types like integers. In our case study, we faced an issue of passing an excessive number of variables to the function to compute arithmetic operations on mixed fractions. struct in C++ allows us to introduce a better approach and reduce complexity while writing procedural and structured programs.

Definition of structures

To understand structures, we first need to refresh our knowledge of variables. We define a variable as a unit that stores information on a single data type ( int, string, and so on). Imagine having a bunch of variables of different data types grouped together under a single roof. That roof, or a user-defined data type, is a structure whose variables are called members. The slides below illustrate this concept.

Get hands-on with 1200+ tech skills courses.