Arrays and Functions

Overview

In modular programming, specific task functions are often created and used or reused for array processing. Array processing functions are usually passed the array and any data necessary to process the array for the given task.

It should be noted that arrays are passed by reference in most current programming languages. Array processing functions must take care not to alter the array unless intended.

Discussion

Arrays are an important complex data type used in almost all programming. We continue to concentrate on simple one dimension arrays also called a list. Most programmers develop a series of user-defined specific task functions that can be used with an array for normal processing. These functions are usually passed the array along with the number of elements within the array. Some functions also pass another piece of data needed for that particular function’s task.

This module covers the displaying the array members on the monitor via calling an array function dedicated to that task.

Pseudocode

Function Main
    Declare Integer Array ages[5]
    
    Assign ages = [49, 48, 26, 19, 16]
    Call DisplayArray(ages)
End

Function DisplayArray (Integer Array array)
    Declare Integer index
    
    For index = 0 to Size(array) - 1
        Output array[index]
    End
End

Output

49
48
26
19
16

Key Terms

array function
A user-defined specific task function designed to process an array.

References

License

Icon for the Creative Commons Attribution-ShareAlike 4.0 International License

Programming Fundamentals Copyright © 2018 by Authors and Contributors is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book