Processing math: 100%
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Engineering LibreTexts

16: Derived Data Types

( \newcommand{\kernel}{\mathrm{null}\,}\)

A derived data type is a user-defined combination of the intrinsic data types. The derived data types are a convenient way to combine or group variables about a particular item.

For example, a 'student' might include a name, identification number, final score, and grade. Each of these pieces of information can be represented with individual variables (as outlined in previous section) as follows:

character(50) :: name
integer :: id
real :: score
character(2) :: grade

However, for multiple students, multiple sets of variables would be required. This can become cumbersome and confusing.

By using a derived data type, these separate pieces of information can be more easily grouped together. The details on defining, declaring and using derived data types are provided in the following sections.

  • 16.1: Definition
    Before a derived data type can be used, it must be defined. The definition will establish which pieces of information will be grouped together.
  • 16.2: Declaration
    Once a derived data type is defined, variables using that definition can be declared.
  • 16.3: Accessing Components
    Once some variables using the derived data type have been declared, the individual components can be accessed.
  • 16.4: Example One
    In this example, we will write a simple program to read two times from the user, time one and time two, and calculate the sum of the two times.
  • 16.5: Arrays of Derived Data
    In addition to declaring single variables based on the derived data type definition, it is possible to declare an array based on the derived data type definition.
  • 16.6: Example Two
    In this example, we will write a simple program to perform some processing for students. The student information will be stored in an array of derived data types.
  • 16.7: Exercises


This page titled 16: Derived Data Types is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Ed Jorgensen via source content that was edited to the style and standards of the LibreTexts platform.

  • Was this article helpful?

Support Center

How can we help?