2. ⢠An array is a group of consective memory
locations with same name and data type.
⢠Simple variable is a single memory location with
unique name and a type. But an Array is collection
of different adjacent memory locations. All these
memory locations have one collective name and
type.
⢠The memory locations in the array are known as
elements of array. The total number of elements in
the array is called length.
⢠The elements of array is accessed with reference
to its position in array, that is call index or
subscript.
WHAT IS ARRAY?
3. DECLARATION OF AN
ARRAY:
Like a regular variable, an array must be declared
before it is used. A typical declaration for an array
in Visual C++ is:
type name [elements];
ďŽ type is a valid type (like int, float...)
ďŽ name is a valid identifier
ďŽ elements field (which is always enclosed in
square brackets []), specifies how many of these
elements the array has to contain.
5. ADVANTAGES OF ARRAY:
ď§Arrays can store a large number of value
with single name.
ď§Arrays are used to process many value
easily and quickly.
ď§The values stored in an array can be sorted
easily.
ď§The search process can be applied on
arrays easily.
8. ONE DIMENSIONAL ARRAY:
A one dimensional array is one in which one
subscript /indices specification is needed to
specify a particular element of array
Declaration :
Data_type array_name [size of array ];
Eg:
Int num[10];
11. TWO DIMENSIONAL ARRAY:
A 2-d array is an array in which each element is
itself an array
i.e int num[4][3]
0 1 2
0
1
2
3
No of
rows
No
of
colu
mns
No of element in
2-D array =M*N
Num [2][1]
13. MEMORY REPRESENTATION:
Total bytes= no of rows*no of columns*size of(base type)
Memory reprsentation in 2-D array:
char A [2][3]
A[0][0] A[0][1] A[0][2] A[1][0] A[1][1] A[1][2]
5001 5002 5003 5004 5005 5006
14. MULTI DIMENSIONAL ARRAY:
An array with dimensions more than two
.The maximum limit of array is compiler
dependent
Declaration:
Data_type name [a][b][c][d][e][f]âŚâŚ.[n];
Array of 3 or more dimensional are not often
use because of huge memory requirement
and complexity involved
16. ARRAY INITIALIZATION:
C++ provides the facility of array initialization at the time of
declaration .General form of array initialization is as:
Type array_name[size 1]âŚ..[size N] ={vale list};
Eg:
Int days_month[12]={31,25,29,03,31,19,20,31,18,20,31,29};
Char string[6]={âaâ,ârâ,âgâ,âyâ,âdâ,â0â};
2-D array are also initialized in same way as linear array
Int cube[4][2]={ 1,3,
4,6,
9,37,
5,78
};
17. UNSIZED ARRAY INITIALIZATION:
C++ allowed you to skip the size of array in an array
initialization statement C++ automatically create an array
big enough to hold all the initializers present
Char S1[] =â first string â;
you skip the size, you must give list of initializers so that
C++ can calculate the size of array
Int val []={3,5,6,2,8,9,6,4};
Int cube [] [2] ={ 1,3,
67,7,
6,87,
};
18. STRING AS ARRAY:
C++ does not have a String data type ,it
impairments string as 1-D character Arrray
.A string as a character array is terminate
by a null character â0â
Char str 1 [11];
Char square [][]={ âfirst stringâ,
âsecond stringâ,
âthird stringâ
};
19. SORTING ARRAYS:
Sorting is a process of arranging
the value of array in a particular
order. An array can be sorted in
two order.
oAscending Order
oDescending Order