Importance of Arrays in a Programming Language

Harsh Gupta - Tech Writer
Arrays play a very important role in almost all programming languages. It provides a very powerful feature which can be used to build a complex type of data structure like the implementation of stacks and queues.

We define arrays as a finite collection of homogenous elements. It means that an array is able to store similar type of items i-e either all integer numbers, all floating numbers, all characters, string etc. but the entire data item should be of same type

Some important points about Array:

· First element of an array has zero index.

· All the data items in array are always stored in consecutive memory locations.

· Arrays are always store under a common heading or a variable name

· An array either be an integer, character, or floating point data item but initialized only on declaration time not afterwards.

· An array can always be read or write through loops

CLASSIFICATION OF AN ARRAY:

There are basically two types of an array:

1. One dimensional array.

2. Two dimensional array.

One dimensional array:

In one dimensional array; only one subscript specification is required to specify a particular element of an array. It can be declared as follow:

data_name variable _name [expression];

Data_name indicates the type of elements to be store in that array, var_name indicates the name of that array and expression indicates the number of items to

be store in that particular array.

That subscript is also known as the size or length of an array and it must be

an integer value.

For example:

int a[9];

It means that a be a integer type array which can store almost 9 elements of integer type and the index starts from zero i-e

a[0], a[1], a[2], -----------------------------------a[8]

And the size of an array is= (upper bound- lower bound) +1 i-e

The size of this array is (8-0) + 1 i-e 9.

ACCESSING ONE DINENSIONAL ARRAY:

An array can be access through loops. For one dimensional array we require only one loop i-e

TWO DIMENSIONAL ARRAYS:

Two dimensional arrays are as a grid. If we have 5 rows and 5 columns then for accessing total 25 elements we required 2 dimensional arrays

Two dimensional arrays can be initialized as:

Int b[3][4]

The first number in the bracket states the number of rows and the second number in the bracket states the number of columns

The meaning of above example is:

'b' is a integer type array having 3 rows and 4 columns.

ACCESSING TWO DIMENSIONAL ARRAYS:

For accessing two dimensional arrays we require two loops.

Published by Harsh Gupta - Tech Writer

I am a part time freelancer and writing is my hobby Some of my websites: http://www.GenericArticles.com http://www.JailBreakingiPhone.com  View profile

  • We define arrays as a finite collection of homogenous elements.
  • First element of an array has zero index.
We define arrays as a finite collection of homogenous elements, i.e. an array is able to store similar type of items i-e either all integer numbers, all floating numbers, all characters, string etc. but the entire data item should be of same type.

To comment, please sign in to your Yahoo! account, or sign up for a new account.