Академический Документы
Профессиональный Документы
Культура Документы
Arrays
Many applications require the processing of Arrays are declared in the same manner as
multiple data items that have common ordinary variables except that each array
characteristics. In such a situation it is name must have the size of the array.
convenient to place such data items in an
Array. Features of Arrays:
An array is a collection of similar data items An array is a derived data type. It is used to
that are sotred under a common name. A represent a collection of elements of the
value in an array is identified by index or same data type.
subscript enclosed in square brackets with The elements can be accessed with base
array name. address (index) and the subscripts define the
The individual data items can be integers, position of the element.
floating point numbers, characters and so, In array the elements are stored in
on, but they must be the same type and same continuous memory location. The starting
storage class. memory location is represented by the array
Each array element is referred by specifying name and it is known as the base address of
the array name with subscript, each the array.
subscript enclosed in square brackets and It is easier to refer the array elements by
each subscript must be a non-negative simply incrementing the value of the
integer. subscript
Thus „n‟ elements array „Q‟ and the .
elements are Array Initialization:
Q[0], Q[l], Q[2], Q[3], …, Q[n-1] The values can be initialized to an array,
The arrays can be used to represent not only when they are declared like ordinary
simple list of value but also task of data variables, otherwise they hold garbage
items in two and three or more dimensions. values.
The array can be initialized in the following
Arrays can be classified into: two ways.
• One - dimensional arrays. i) At compile time
• Two - dimensional arrays. ii) At run time
• Multi - dimensional arrays.
Entering data in to the array:
One - dimensional arrays: The data can be entered into an array using
The collection of data can be stored under the input statement as well as loop
one variable I statement as well as loop statements.
statements name using only one subscript,
such a variable is called the one-dimensional Two dimensional array:
array. Two dimensional arrays are used in situation
where a table of values need to be stored in
Array declaration: an array.
Syntax:
The individual elements are identified by
void fun 1 (int , int [ ] ) ;
index or subscript of an array, from the
main( )
above example.
{
a[0][0] a[0][1] a[0][2]
int a[10], n;
a[1][0] a[1][1] a[1][2]
……
a[2][0] a[2][1] a[2][2]
……
fun 1 (n, a)
Initialising a two dimensional array: ……
Like one dimensional array, the values can
……
be initialised to the two dimensional arrays
}
at the time of declaration.
void fun 1 (x, ar [])
{
Example: int x, ar [10] ;
int stud [4] [2] =
{
Array of Characters (string):
{ 9814,90 },
A string is a collection of characters. A
{ 9815, 95 },
string constant is a one dimensional array of
{ 9816, 82 }
Join Us on FB :
Join US on Whatsapp