Throughout this course, we have defined many different variable types like, int
and char
. These are known as the basic types and are built-in to C.
We’ve also defined data types like arrays and pointers which are known as derived types. Derived types tend to be a collection of basic types to create a new, more powerful data type. We will now explore another derived type, the structure.
In C, structures allow programmers to create user-defined data types. Structures, like arrays, allow you to collect many data types into one single data type. But unlike arrays, structures can be a collection of multiple data types.
The above image represents a structure and the different types of variables contained within it. This type of “packaging” is beneficial because it helps build and pass around logically related data in a single user-defined data type.
Instructions
Take a look at and run the code in the workspace. Notice in the script.c file all the variables that are defined. Think about how you could use structures to organize the data.