Monday, January 19, 2009

3rd-learnings of the week(Colegado)

In computer science, an array is a data structure consisting of a group of elements that are accessed by indexing. In most programming languages each element has the same data type and the array occupies a contiguous area of storage.
Arrays permit constant time (O(1)) random access to individual elements, which is optimal, but moving elements requires time proportional to the number of elements moved. On actual hardware, the presence of e.g. caches can make sequential iteration over an array noticeably faster than random access — a consequence of arrays having good locality of reference because their elements occupy contiguous memory locations — but this does not change the asymptotic complexity of access. Likewise, there are often facilities (such as memcpy) which can be used to move contiguous blocks of array elements faster than one can do through individual element access, but that does not change the asymptotic complexity either.

Memory-wise, arrays are compact data structures with no per-element overhead. There may be a per-array overhead, e.g. to store index bounds, but this is language-dependent. It can also happen that elements stored in an array require less memory than the same elements stored in individual variables, because several array elements can be stored in a single word; such arrays are often called packed arrays.

Array is a collection of variables of the same data type that is referenced by a common name. The two declarations for arrays number and answer can be combined into a single declaration:
int number[100] , answer [25];
Arrays can give initial values during the declaration. This is called array initialization..
int Array1[5]={25, 5, 7, 11, 163};

The general form for any declaration is as follows:

type array_name[size];
Where:
type is any valid data type in Turbo C which declares the type of values that array will hold.
array_name is a valid variable name which will name the array.
size defines how many elements the array will hold.

No comments: