Site hosted by Angelfire.com: Build your free website today!

Single Dimensional Arrays 

by Vangelis Livadiotis

 

An array is a way of organizing data in memory, and is an example of a data structure. (*) The way which the data is kept in an array is static. When we first declare an array (eg. var months:array[1..12] of string[9];), we tell the processor to reserve 12 spaces in memory to hold 12 strings of length 9. That of course can differ, it can be an array of 200 items and it can contain boolean, integer values etc.

When we analyze the variable declaration var months:array[1..12] of string[9] we get:

 

var months array[1..12] of string[9]
The name of the array. This is its type (an array obviously) and it will contain 12 items starting from number 1. In Pascal this can vary, you can make it start from any number you wish until any number after that. This affects the part where you enter or want to access a part of the array. The first element in var example: array[4..7] is example[4]. Note: Other programming languages like C and Java don't have this option and start directly from array[0.. whatever the limit]. This declares what type of data the array will hold. In this example it will hold data of type string since we want to keep the month names. The nine at the end indicates that the strings will be of length nine.

 

Instructions:    

The applet below is a graphical demonstration of how an array is created and how information is added to it. It is an array of integers and you can create an array from 0 item to 9 (it is only limited for graphic purposes) and you can add an item (integer) at every part of the list (which is limited from 0 to 97). You must first enter an array name and an array length and press Create. To add an element each time fill in the position and number to insert areas and press Insert. To restart the array simply press Clear.

 

Home | Arrays | Arrays2 |Queues1 | Queues2 | Stacks | Arguments | Pointers |

Binary Search Tree

Copyright June 2005 - Author Vangelis Livadiotis