You are on page 1of 7

ARRA

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

decided at compile time decided at run time also .

int n
;

ACS1NAP Cino > 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.

① int A [3) [4) =


{ { 1,2 , 3,43 {, 2,4 , 6,8 } {3
, , 5,79} };
#
o
Array will be stored

i
inside stack .

A- [ 1) [ D= 15

Array of pointers
*
② int A- [3) ; -

A- [of new int -43 ; # Memory is


i

2
A [ D= new int [4) i created inside

A [ 2) =
new int -143 ; heap .

A- [i )[2) = 15 ; # we can access


array
of pointers in the same

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 .

That's and Ctt do not


why c start
array
indene with 1 for operation,
.

Only one entree

time taken
by the program will increase and

this will make the tower


program .

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

now now , MOWZ


,

Add ( AED -12) ) =


zoo +
[41-2]*2=212
Add ( A- [2) (3)1=200 t
[2%+3]*2=222

Ati) -63 ) [ inn Addlfilfi )) D)


*
Add ( =
Lot tj ]*w -

Lotfi -
Ifn +
(j -
W

Y 6
operations operations
COLUMNMA.JO#

A taiH
Col 0
/ coli
/ Col 2
/ Col 3

ADD ( AED -12) ) = 200 -1 [2*341]*2=214


ADD ( A -4513) ) =
200 + [3%+1]*2 =
220

-
ADD ( Ali] fj) ) =
Lot (jam ti ) w

FORMULASF0R#ARRAYS

A- [ d1][d2) @ 3) Cd4] ; 4 D ARRAY

Rowmajor

ADD ( Ali ,
]Ljy ]) =
Lot [ ii. dated ,
-

dy t
iz
-
d
,
-

dy t iztdy tiy ]*w

(
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

ADD ( Ali ] [ iz][is][ in] )


,
=
Lot [i ,
-
dated ;D ,
t
iz
-
d
,
-

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

int A- [e) Im][ ) ; n

ROWMR

The)) Lotfi
-

Add ( Ati] join the]


-
=
min + w

(0tUMNMAJR

Jfk) ) [time jolt i]


-

Add ( Afi ) =
Lot + w

You might also like