Professional Documents
Culture Documents
scalar I n
int n = 10 ; 2
bytes
100/101
int A- [5] ;
✓
o i z 3 4
A- [23=15 ; A # 10
bytes
vector 204120432%2041 2051g ,
DECLARATIONOFARRAYSO I 2 3 4
① int A- [53 ; a
garbage
0 I 2 3 4
② int A- [ 5) =
{ 2,4>6 8,103 , ; A
0 I 2 3 4
③ int A- [ 5) ={ 2,4 } ; A
→
Rest of the elements get
automatically initialized by O .
o , z z u
④ int A- [ 5) =
{o } ; A
O l Z 3 Y 5
⑤ int AL ) =
{ 2,4 , 6,8 , 10,12 } A →
Depending upon the
number of elements ,
size
of the
array is
automatically
allocated .
int A- [5) =
{ 2,5 ,
4 , 9,83 ; o i z 3 4
A
20%43%47208/9 →
" "
Array addresses are
printfl t d A- [ 2) ) ; contagious
#
.
, .
" "
printfl Id TA ) ) forli
%P
,
2 ; -_
Osias ;i++ ,
d Ati ))
" "
pointfl t U
.
,
;
yd ; ya t t
"
printfl , ;
for printing
address .
STATICVSDYNAMIARRAYSiz.ee
# ↳
of the
array
size of the
is static
array is
dynamic
→
Once an
array is created , it's size cannot be modified .
Inc In
→ of the is → The of the be
size
array size
array can
int n
;
int A- In] ;
void main )
{
int A- [53 ;
int *
p ;
p[ 03=5
To
/
I
^
HEAP
-
¥1
\
Ctt
p= new int [ s) ;
STACK
( int
Yigal !gs
-
c p -
-
size of linen ;
,
i main c)
!
I CODE
=L
Ctt
free
;]
delete
Lp) ;
p otherwise
MEMORY LEAK
} shortage of memory .
ONEWAYOFINCREASINGSIZEOFARRIints.pe
*
new int [53 ;
int
q= new int [ 10) ;
p
)
forli - o
;
is 5
;
itt )
x
gli ) -
pci ) g-
H
delete [ Ip ;
×
4¥11
-11
o l 2 3 Y S 6 7 8 9
p=q ;
NULL ;
q
=
D-AR#AY
2.
i
inside stack .
A- [ 1) [ D= 15
Array of pointers
*
② int A- [3) ; -
2
A [ D= new int [4) i created inside
A [ 2) =
new int -143 ; heap .
way.
③ A-
He int
* *
A ; # All the is
4- A = new int
*
[3) ; allocated
memory
in heap .
Alo)= Lu]
-
O
new int ;
2
,
¥3 A [ D= new int [4) i
A [ 2) =
new int [4] ;
for
:÷t¥¥÷÷÷÷
Li ; i <3 ; it "
Ii
o
-
"
:
:S
:÷÷÷÷:
"
" ni
H
0WC0MPlLERGENERATESFoRMULAF0RADDRESSOFANt
int A- [ 5] =
{ 3,5 , 8,4 , 23 ;
¥14121
( >
200/1=34/56/7208/209
to
ADD ( A E3) ) =
200 t 3*2 = 206
ADD ( A- [ 3) ) =
Lot 3*2
ADD ( Afi))
=
Lot it w
- FORMULA
[
f f Size of No of operations =2
Base datatype .
Inder
Address
*
ADD ( Afi)) = Lot (i 1) -
w
-
Formula , when indices are
from onwards
starting one .
No of operations =3
# More time
consuming .
time taken
by the program will increase and
ROW MAJOR
-
5 6 8 9 10 11
[ 3) [ 4) ;
3 4 7
-
O l 2
int A-
A /ktaaa9/ m n
/
22
2001 , 43
/
4 6 8 10 12 14 16 18 20
Lotfi -
Ifn +
(j -
W
Y 6
operations operations
COLUMNMA.JO#
A taiH
Col 0
/ coli
/ Col 2
/ Col 3
-
ADD ( Ali] fj) ) =
Lot (jam ti ) w
FORMULASF0R#ARRAYS
Rowmajor
ADD ( Ali ,
]Ljy ]) =
Lot [ ii. dated ,
-
dy t
iz
-
d
,
-
(
Dlumntajor
( Ali ] [ is][is][ in] ) [ iytdz iz'd ,
- *
ADD ,
=
Lot did , +
iztedz'd , t + i
, ] w .
c-
RowMAJORFORn# C0LUMNMAJoRfD
Lot piling.ir ) -
w ↳ +
Enid gig:] : .
( self tried )
( please check )
A- [ d1][d2) @ 3) ( d 43 ; 4 D ARRAY HORNER 'S RULE
Rowmajor
dy t iztdy tiy ]%
- - -
-
3 z l
UD → 3+2 + I
5D → 4 t 3+2+1
ND → n -
I t n -
2 t n -
3 . . . ..
+ I =
n
2
0cm )
* -
dated ;D
- -
in t
iz dy t
iz d dy ti
,
, ,
iy t
dy ( iz t is .dz t i
,
'd;D
, ]
iy t
dy [ iz -1
dz[ iz -1
if dz]
T t t
Oln )
F0RMULAFoR#ARRAYS
ROWMR
The)) Lotfi
-
(0tUMNMAJR
Add ( Afi ) =
Lot + w