Professional Documents
Culture Documents
CS3251 (UNIT 2) NOTES EduEngg
CS3251 (UNIT 2) NOTES EduEngg
CS3251 (UNIT 2) NOTES EduEngg
WEBSITE: www.eduengineering.in
TELEGRAM: @eduengineering
UNIT- I
ARRA YS AND STRIMG
have
Thasa
Thasa dala Yament in consocutive mamoy
stored
elomenb t h a onay aa UndeT albo known
ard o7 fervad by an
localen
as Sub &ipt
Do claLalhon oArrays
wd
must e daclauad bayore Ling
being wed
An a7ay
aaurame l'si]
Syntot dalo tupe
storemb, chas,fled
datalyre-whot
knd values t Can
deubla)
datalyre to derdfy tha aay
Name
maumum nume alu fhak the a ra
the
Can held
tha stao rnent declaves
a to ke an
t alo)-
xampe der
Tn tho ovray
Cenlainng to numke 1s
ay ens th n-i
m
ad
Stovb
rd ,
Flamerh>15
0:iu it+)
or(
num J Loo
olamants
Cal caulatinq tha addrass f ra
onsocaute
dala elemonh n
An aray storos al kase addess (la)
the
the
memony lcauens Slovugju sulffcient
a7ray Canpy b alabte!
element i h o alaualal
addws h e sk elemenh Can ip
Can
data
The ocdross of othe
tha base adress
Ung 58, 311
58, 55, S0,
tmaks [J:feg,s1, address: 1oo
address io
an
a n aray maks [ 6 kae
in J marks
[6J
the address
colculala
7
58
9 57 AJ
012
ma ko foJ toh
2(5-0)
loco
[hJ)
9ddvess (ma.ls Ooo
he kraw tha
thcecre
,uord me bes
2-tes
storad
e lome nb lowo bauwd t
uppo bourd
-
ongth
auts in a0y Just alloaking epoce
spece
Stor
a7ray,
uo
au
Just alloaling
tn tho a r
an
declae
aray
when
hen we
no valos
ao stor
stora J
the
elomenb.
thee Qua
a a y , thoe ao throe uays
thre
aUS
o t htha
e ava
To Storc
Valuos
element al
element
a the
te time declaual
lazali.
the array
Tribaline
Initialing koyboad
the keyhoad
the
Valuos rom elomens
elamen
Tnputng a
udrdi riiv
diu
deuY
a
Vaues to
Assqning declaralon
declaalon
during nbialrmal af
at
the avrays
also e . thitialn
IniIri tiaum
Can alsSo
When an
an
array when a n array
Elemen f the a o totho
ho
ar
V aa
rabblle
ess ..
daclatalsn
a Vaue for eveu
Value tor eveu
the me
me
hood
Provide
we
s intialmed
element
the arra
2 list Va lue
auay name Lsine7
=
tyre
, 95, 8 d.
navks öJ =so, 85, declasad, tha has
ha
it marks
declacd that
nama
an array Wth
Wth
elamenta
elameni
to store
endy
enoyh Space at the
the bme
time da
daclaxalon,
clasaluon,
at
ibiak m1nq the aay
while n auay.
Cmit the
tha
S he
the
the poramme may
()
80 85 q0
t maukalhJ: /8o, 85, 40,5, 7
ttmauks6J = S 0, 757
qo 95
int maks CsJ: D3
eloment f ke
to pu the Value tor each
bxecutad
6LLLay
tht aLh
forLi-0 1 5 i t t )
San'7d", da[i J);
values t indevidua! elamenb
*Rssgning
evauales to the daatye ef the
Vake thal
Any ndtvi dua ausay lamerb
asig nad
to tho
Crvay can e
aray ( e wiHan as
assignment Slateme nt con
A ple
Sunple
marks [aJ 98
ray to anothor a7yay,
One
hWo Cannst as ign
hare thas sama bpe ad
pe ard 9g.mp
evan f tho two arays
ndriduol elornan! lavel
n a17a aa he
nt 1, auD5], ar J
aTE5) , 2 , 3,4,5
for (i-0 i5 i#)
Dimen Sional
TO wsing two
uing
au Spoufod
A t w o dmensforal
A dorotes
tes rocw
rocw ard the othar
other
whoo. ono Subeipt dono
Subsc pb
dle noles cskumn
dimensional ATTOS
ikclaring two adoclared before
must ke
arrays
The
The two
two
dimensional
Stalemant
Stalemant
Cornpiler
tels the Conp
tells le
doclasalo
doclaualuon
eoch elomant
use!.T h o te
being
array,ho dala
tha dimension
the name ard the
Simeeach
each dimarsion
n the amay
Syntax
dola type yname oueSie] cslunn sye];
aLJ Co aL121.
al2[o
tuoo
dimensional anay
T tialining 9}
, 2, a, 4,5,6,7,
tht afaJCa] =
amensiona! array
array dene
dene
two
Tha nibialinaticn of a
witten
Con alo e
Statement
brow. The akova
ECRNL
Unit:
Subject Code/Title: CS 3251- Programming in C
c l u d o sldohr
tht maun ?
println");
8
for (y:0, j<a j+)
prt 7d t ", atiGI):
3
3
Strings a nul txmunated
tearunated
a string
In
In cC langcua
anguage,
afte the last cler, a
chaa
chaocte
This means
erd the
the erd
tho ko
& stored to Sgnity
chaacte L'lo')
nul
n ll
enclasad
charote lo at Hhe od delaulk.
nell
null
on sling s
operauons
Lonqth a string
Ornporo0S tuo 97ing
# hcluco Kstdo.h
ro7d maus t)
len
strLso,
{zo,
Cha
en yd ", kn);
Prontf( Length q strng
oul pd qrammi
Ente tha shrng
Lenqh strin
Comsaf nq tW Sings
SI ard S2 aua tuo slrgs then Compai two
l) gve
ett he those osults
Smnq
Shings eddal
SI and S ae S) wlCome afle 52
SI>S2 when dcon auj ocdos
procodos S2
dctionci oydes S
$I s S , when n chae
chas cBes
tte w
u
each and evey
the turo Strngs chzdocers
chalacders aa e
To Compac. tha
tho
all
Tall
oth tho Srings. Tf
Compauad m sad to
a o Caud
be edual
to be ecal
tha buwo SBings some lonqh
seme nqh
Came than tuD
tuv Strings aue
Strings
Qe
the t.
ve frst check
whethe
on morhg
ass
ahedd a
ahad
hen thea bno ppint aa a
rot
not
Same
Sane
not, too
t o Strings
Strings then wO
meanS
thaf tha
tle
sama
Sama langth
angth, Then wo
5raght toay oThe a l l the chasaders
the
chaaders
tuo Sdrings
aa
check
chock i all 1
tha chaiactes to
efual sef b
Compauoo chaacto ythan
Chaacke
whlo Slr2[iJ!
Str3jJ str2C -
str3 LJ "lo'
Concatenated stmng 2:
print"The
puts (si73);
geth)
ne tum oD
Copying Sirg
usad
bcopy tha Contens f ono String
Stvin oPy
Cto anothes String
ihclude 1 stadio.hs
Yoid maun)
62 C50J
chas Si [5o3
nt
Print Enlo the sringIn")
geb lsi))
0
while (siL1! '\o')
Sa[ S[i3;
Oulud
Fnle tho Stnnq heltoma
Binay Seaich
Soo chin techriduo Sc0rch reduires the
Seachi the press o doleamining Binay 'ascanding
Rsd e orted
Present alaoithm
whetho on elomant Birauy
ceach
elemenb or nof
Orde. The tha eloment
|a ren st beqins by Cornparing
mudde
Present at tho
inea Saoich that s
tochndue. t h e Rst.
he
I the Sunplas!al n e end ot
tha
these iia matck then
The Seach egins Tf lecalen o
loalsn
the rduin ard the
ListSeachel for
st erds
Soanchmudde element eturned
b etumed
ntil thé eloment muddla e lament
element n e yone
with
elamantO end 1
lst s the
tho
mus
math
ln "); to
prnif ("Ente the suge famay T h s process
el
e la
omme
ennt
t
edaal
eua t
the s t
Scauch
Scarf d " dn); elemens"). the Seaich
middle
eloment or
elament that io
n)C"Ente
tha aray the elament taB
one
ony Seadh element
for (ico idn;itt) Contains
edualto the
da[rT); not
Scanfl" d ",
Prof(Entee the
elament
bseach)iclude stdio h>
Banf . d " , ar): nclude2 <wnio. h>.
elemenh ")
printf elament fourd'") Print
fTenla
the
Se lochan Sor
Je ction Gorl dolemines
Last n- The e
and
nid: (vs last)) the mi rimum of the s1
tha e lomad
a
ith
Ahile ( s l l a s ) Scoaps 1t
assumed minamurn unde
tho
ftafmid] <z) athe avray Contaun n
an may
xtra pro9rams
mun
Mol additon
for (i in;j<n j14) #nc ludo Astdro h>
Veid mainl)
(o[muiJ>a ji) 2 c[5JT5]
mun int a bL6J bDSJ[s3,
ht j,m,n;
(mun-i)
Pf Ente the ww col s.rge ")
temp a[AI SLan(1d7d"Am, dn)
pritf Fnl Halriz A tlmi");
for(i o 7am ;it)
a[mun : temp
Slj-o jan; j+)
3
Pnntf "sovked Elmbs \n"); Scanf(A", daCiJ1);
li-o isn, is+)
3
Print d " al:J), Prinf("Entes the B Hanx £lemenb ");
lico 1am,1++)
oulput
Ele the no tlemen h 5
Fol-on;Jr+)
63
39 2
Scanf (yd", ibE:3);
Sorte e lameni
fo Ljeo;jsn ir+)
3
3
01U ye r DEPARTMENT OF
SCIENCE AND HUMANITIES
Subject Code/Title: cS 3251- Programming in C Unit:
Scalad maln n)
Pnlf Re cutdand maln?") Printf
6li-o iam ++ tor liro im 7tt)
pvintfn")
Pntf In")
forjo jan j++)
for ljro, jen r+)
Prntf(d", afJ[j7)
prntf (yd , ctiJ1)
3 3
Cpu
Fnto the Simp a matr
3
Scalng Halv Vaue ANal nx
ne the
2
n c lude <tonio. h 2
Foi- jn jra)
aCEJ sf
Downloaded from : www.eduengineering.in
Subject Code/Title: CS 3251- Programming in C Unit:
Yoid man t )
fo +jn J7)
flaL)J: =aljJ)
int atoJ, ij,t,n made t+
Lmode!-o))
F (tmoda Smar Jd&
loa me dian =mode. bCkJ : arrJ; kt
2 k=o ; ma7
Cc-=n)
PrntyThauo no meda ) cupu
55
else Enl the Lmu
En the humbors
pintf Nodo ")
2
Two marks
Define frrvay
a a cstletusn Sumlas Valua
Avalue aa
stora bntinunu momarylocalusrs . l
oni ed
nane Tha elemonts e Og
Shae a lornmon
Yolues
in Sacuonial osdeo
t afa
arras tn C
Crealo an array
Can
Houw
locw
Croala an array
6fereal nkox
> Kauayname L5ieJ;
Syrtox <dala ype
Fample: iat afo]
uith the he the undox Values
Aays
are re fe7enced
tha riabla avray.
as o n
notaton to ropvesent
tha he aray Contains n tegers thon the
Assume
*
dend tthe ovue ard the
st elernent ai
cslumn
wws and [ 7efors
avaîlale n cC
st the
Strn9 Juncdion
String
getcha C) 2 le chara cte Junctions
Put chau c2
?
String with example
5 Define A sring
Qray
characters callad a Sing.
null
chaacte
Chaiacte o.
lo.
tem nalad by
a
Her2
Forxaple Conside CProqrammirg
Compilo e ntanters
tanters
When, Complai en
a String. chaa cte lo
Cpr9ammir9 chaacle
nul
null
automati cally arpends a
slings,
a he end o shing.
" e Prgramming
Erampla.. Cha c LJ
re on extmple
tor hibaialion fsrin aray
b stdi o. h>
hclude
Yod maus iven Stnrg He lo.
chas str CJ: Hello "
Prinf" yiven shing : 7.s ", Str)
3
Downloaded from : www.eduengineering.in cHENNAI DEPARTMENT OF
SCIENCE AND
HUMANITIES
HNL
Subject Code/Title: CS 3251-Programming in C Unit:
mean by Serting
9 hal i a is} e mens
ss arangng
the
Proe
Sorbin
Soring
aula orda There ae manuy types S o ting
c a part
techmd u o
B u b b l e Bort
Tnserken sort
Seleckon Sovt
ui ck Sovt
*Merqe sort
*Heap sovt