Skip to main content
Engineering LibreTexts

16: Derived Data Types

  • Page ID
    54225
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    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; a detailed edit history is available upon request.

    • Was this article helpful?