For this module, you should read the following sections of this PDF document;
Section #3 - Complex Data Types
Read again this section with a focus on the struct & union material
While we provide a PDF version of the above-mentioned tutorial, you might want to follow this link to Nick Parlante's web
site and download the latest version and peruse the excellent material available there.
In this exercise, we are going to take our structs and, based on the fact they introduce a new data type
in the language, use them everywhere we have been using elementary data types;
As parameters to functions
As return values
As elements of an array
As elements of a dynamically allocated array
Then only, we will examine how they might be used as "pseudo-classes".
This first exercise will illustrate how we may manipulate arrays of struct elements.
You will see that everything we learned about arrays still applies and what you read about structs nicely integrates with it.
Video Duration - / Development Environment - Linux
Beyond using structs as a new data type, which may therefore be leverage in arrays and dynamical arrays by the use of pointers,
it is also frequent to use structs to represent a new type of application-domain's "object".
This is very similar to the ideas you've been already exposed to in languages such as Java or C++ when dealing with Classes
and their Instances.
Unlike real object-oriented languages, we do not have the luxury of packing together functions and structs.
Instead, we may write a struct representing the data-aspect of things and then write a bunch of functions,
each taking as first parameter an instance of such a struct. If we name this first parameter "this" some of you might see better
how it relates to what C++ does auto-magically for you.
Regardless of such efforts, we are not using an object oriented languages so we won't be able to get polymorphism or inheritance.
This, however, doesn't mean we should not structure our projects in a rationale and even "objects-like" manner.
This folder will show you how it is done in an exercise meant to define a new type of "objects" - re-sizable arrays of ints.