Single/One Dimensional Array
An array in which all the elements are stored in a unidirectional order and using one subscript to access the elements are called as one Dimensional array.
An array in which all the elements are stored in a unidirectional order and using one subscript to access the elements are called as one Dimensional array.
Syntax
<Data type> <array variable>[SIZE]
Ex:
int a[5];
Memory Diagram
In
the above Example the array a is Declared as Integer Array and it can store 5 integer values each of
which occupies 2 Bytes .Since total Array occupies (2*5)10 Bytes of Memory as
shown below
a --------> Array name
|
a[0] a[1] a[2] a[3] a[4] --------> Array index
NOTE
1.Subscript
is a non negative integer enclosed in [ ] placed immediately after
the array name without any space.
the array name without any space.
2.In
Arrays by default array Index starts with 0.
3.Total
array size(in bytes)= Length of array * size of data type
Array Initialization
An
array variable can be initialized with a element as given below.
Syntax
Data
type arrayname={value1,value2,
value3,valu4……………..value n}
Example:
int a[5]={1,2,3,4,5};
In
this example first value stored in First Block, second value stored in second
block and so on ….. as shown below.
a[0]=1
; a[1]=2 ; a[2]=3 ;a[3]=4; a[4]=5.
1
|
2
|
3
|
4
|
5
|
a[0] a[1] a[2] a[3] a[4]
Example
|


01:46
Unknown
0 comments:
Post a Comment