Programming Fundamentals/Arrays and Functions

Overview

edit

In modular programming, specific task functions are often created and used/reused for array processing. Array processing functions are usually passed with 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

edit

Arrays are an important complex data type. 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 either passed with the array along with the number of elements within the array, or just the array itself if the programming language has functions to determine current array size. Some functions also accept additional parameters necessary for that particular function’s task.

This module covers displaying array members by calling an array function dedicated to that task.

Pseudocode

edit
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

edit
49
48
26
19
16

Key Terms

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

References

edit