411 REFERENCE · Wikibooks
Programming Fundamentals/Arrays and Functions
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Overview
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
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
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
cnx.org: Programming Fundamentals – A Modular Structured Approach using C++
Wikiversity: Computer Programming