You are on page 1of 20

t u n e t i .

A
tunthon is o
quoup o
katomes nur togethe1 to
po Orm a task

Suntan

un ttion-type tun-namu (paiameta.


livt)

OCal yautable declaiahon

enecutable <tattnent
eneutablt Stattmnt 2

uetuir Statrment

OSt dqined \unction

sCx deined unctions haue contaun ed

the bloc o tatements wnich ale


tten by -tnt use to peorm a
tash.
n
to make a, use-detined kurchop
we need to estabtish thiee etement thar

at detattd to funttions .

Funthon dclinitiorn
Funttion call
Funci on declaa ati orn

Function ost o Call

A tunction call i ar impovtant pait ofc


Puosammin4 tanguag
I t i s called ivide a puouam whenu
ieauired to call a tunction

Funttion dulalation
dKe vauiab lu, allFun ctions in a C070
-Kam nmult be detaled, bey0Y h
ae
inuoked
A tunetion de ttaration contSts 01 tou
nats

tuntion type (uetun


typt)
nchon naMt
Poamttu ut
teminating semicolon
qntan
Fnttiont
typetunthon-nam (raiamth
R e c u i s i o n

fon i
Receutsio
tut pro cest in whih a

f u n e i o n
t jtsetE up to n number o)

times

Synta

Main

pTiuttCtis iS an taample o u eun


man

outpu
emaml 1c O} i e CuTPM on
tui is an

Atunttion to euauat tac tovial 0tn

atn-faetovs al Cint n)

int faut

etu n C)

else

tact aad h tattotia Cn-1) 3


etunltat) S
Stuetur
Sttuttue it detinee datatsple
a uuet

allailabtt in tnat auo w t0 CO mbin


data items
o dil, etent Kindd
Synta
ttuct sttuctuue- hame

data type membev-1;


data -

type membu 2

data-
typt em be N

namnlt
enarup tt to deund a
tutu t tov
ermntoy in an nhy

Stuct emnloy ee

int id
cha narne [2o,

Hoat salajy
is acollection O data types o
sae typeit can be int that f10at,

foublt een a Sttucule

Syuta

datatyr
alay nameannay n2e

nample

intStuden t_ ma vks l20J


chal stud ent- narme Lio],
ioc umbus TS,

uions
data-tspe va1 iable
A union is a
spetial
10C thaat auloo to stove dilerew
data typu in the Same mem or
(OCaion.

on-namt

aratype' memb 1
data- typt Member 2;

data tp N)
Menmov y allocation

wion emP
cha x
ttoar
Memovy shaain
ad allocatu

e C i o n v aTfauk)
t0rage
eaual to
tou by tu lalgest on.

A poiuer is a uauiable ohich capablt.


Ot coving tne addrs 0a vauiab.

Synta

datatype oIut hame a

int ptr.

Reaence opeaoY
uelueMce opt ator oftun caued
asA dd1e
ot opuarot Vinq Cam per sand ) op ero
-60¥ o th a vau ab le Juuini a me
18Ca on alio uown add eM

o 9uen
vai labI

Signtaa

jut a
ptr & a
a' is stoved
te addies ol u aliab le
In viable

De-uefelence 0pevaro y

Dt - ueen cnG 0 yaue at ope


-ator wucn s dtn0 ted by asteriskC
It helps 10
uetliling thu ualle
ho m
t wnich,s
minO14 Ocatio
Stoted n tne
oi uer uali ab e.
ynta

wtot
ur a
pt
Nutl oiutt
Ä

ult Can tieatt null


a
pojuttu by
aviquinq null vaue duig tu
DOiutt dtelaiahon
twe mttued is utjul whn
you do
nt have ay addges amGned to
t neiut
Aul poiutt alway
Valle 0. Contau ns
uta
+includ ctdio. h>
ut majn )

nutt(tue vallut o1 PtT is


%uln", Pt1
etuin0
categOrq Oj funitons
)

A ntion, depend+u on whetue


uot aud
atqumeAD aL present
toheth Y
vale is uetuuued oY
ot Ma beuon to ont o th
tottowiug Catt g0tie
catego ry Funetio nu With no algu
and no uetun
valne

OIth aGs no RV

C with al and one RU

no a wtn RU,

NO
aAqumunts and no letul ualL
ththun o
uncti0o has no algGumh It
does
ecieue
data tom the
calling tunttion
mi1au wnun it n0t
d0W uetuun a.

VauLt tue caluing tunetion docs


eciede awy nb
data +tom the callca
unction
"
et
hue isno d ara ttany btwu u

Calling tunision nd eald WuATn


contto f
Funcion tnction 2 )
AO INoUG

fun cti on 2l)

cOnt t l

enam nle

#incude Cstdio. h>


oid add cuoi d
void main c)

add

0Id ada C void)

0rintt C Eutu a u two intege


Scan C1. d Jd , Ln, ky
"

porint tttne um ii d", Swm)

Output

Entu a tuoo nttges 2 y


6
M g u m u r s
tibut no uetuun'valuu

UeN
a Ation calu is made, ony a.

ALtMt valULO OV aLtual


angunm n
sassed ntd tAe calt tunetfon

hlnat ocCOui in 1de tnt Vunih ôn wil


halle n0 eect on te vailabl ied

in the atuat naamitti tit

Value o aigs
Pun Chon2)
tntioN

tunttjon 2 (a)
N O Tetuln

val.

#iuctude rtdi0.h?

void add ciw, iut ),


void maint.)

lutegey)
tu0o
gniC2utu a
add Ca Y)
Void adct cint a i nt b )
jut um
um atb

iutt the yuM is 7.d um

Output:
Entu auy two iuttgss 29
fhe nLM i

Algumnts o ith utuin ually

t e tuwwtioo. v auuu utcieues data Hom


the cauing tunthon tuiough
-urn but docs not Send baR a alu,

Katuet, ir divplass tne u w t ov calcud


- ahjons at tuc tumina.

Punetibn 2 Ct)
unthion f()

funtion 2 Ca

u e t u n (o)
intuude lstdio. h>
t add. Ctnt iut )
main

t y um
o iwt t eutts a tuoo uttga;")
Scant "% d 7. d's kni kq),
Sum

sintt (" tht 8m is


ed um )

ut add Cint a, ivut b)

a+ b

6utput,
ittgeui 2 y
ho0huoo
u n it
Nto aaqumnUS but UctuuJ a u al

tnete COula be otcaion n t r we


mam ne ed to design Puntttons that
may not take any ai qum but
uetuw a talu to Te Calling unuti

inctudt ttio. h
iur add CAroid )
void main )

um adà );
n t t u e Sum is 7d" Cum

jut add Cuoid

P.

p i t ( eutti auy two futtgus *);

C nt

y
OwPut

mi 6,
t
piente
rLLntebttween Stturu
and
uon

sttuetu Onon.
th kuy wôvd Stiu tue heuywo id u
-ct is e d to -on is
used to
deyiu t t u t t u e deyine' a ion0

Whtna uasiable is klnen a tariable îr


asou atd wjth a assoctattd WiTn a

Sttu ttuit, the wuoo the com


ompilu 'atl oCarU .-Di auLD caru
tue memer bu
th mi or y tovN
conidu ug the
each MuMbu
S2e Ot tne laiquh
the she F t u
te Ís qeatuer the wi
S2e o
than oY aual tD -On is caual to

Tue laujet
Si2e O
It rmenmber
Memor auocated

ach e n ber
hared by
i t i n a sttu
ncluiduaj

-ue i aisnec4 Menub

w o t Korag
e a 0v locahion
ralle Altetiug ttue uauWe Of
a m umbev w itl noruls valus D ay
Altug
t
Other Membeik 0 O t u muwbt
wil alttu
Sttuctule
otuer nernba

Ualu

udiuidual men bev w y , one mumbu


ACceiug Can be acceled
fnen es can be acttssa tim
at
a t a th

jutialtation Seu a member1


0uly tne fini
Ov membes o a
OraStuctuu
menbS. umon Ca
Can tutialfnt
he i w a l t d

at One
Stuctue
d a t a s t u t t u t e A datatypr t a t
a Storu diyyeuntT
ensis ting o
data tyru in
colltetion OelemMe

t
nt t a h ideutii Sarne mn®r

-ed by t h . oCan6 n.
asia fnd e

a 0 st 6ove di veent:
ov
atatl emnti 0 datatyry
same data &ingie mt
ty pe in onti
uuou mumor
0 Canou

is pombe fo tt is po si ble to
acs o punu
Oa ttuetw
oltmnr i y name and h
t indun dot 0neato

O Kywovd t i u t {uwo d.

Sauh l unmut
has Tu Sam Can be diyyeetnt

t to aCCek to ae CAA
Stiucteniploy tte

nt id
Cha hame t2o.
hoat sal aiy

Memon4 atiocandN 0, t e
ttu ctl p oytu
(O04

410

hd id chaa ame ( to.


toat ,
Stuctemployete
lt
ind id
CthaAnarmelto S siae o (tut) =y
byte
Hoat sauay Sit 0 thai) lbye
ineav seanch

tine a l Searth i alld Called a seaun

- tial 9earch
kinea Seavch n e i to ind whtu
a umbei r eSnr n an auy

t its
pu then at wna Location
mle CompaA each edt m n t wIth t a
talgt elemet
nhi we rind ir
uL the.t ends

iead tne scalch d e m n r


Step - inst,
Scarch tlemnG with
Skp 2 comnat tne
iselemt in t asia
th
Matthed difplauu
Sttp 3 If botn ali

talget
tlemMr i o wnd
tumnatt The lteal
and
Seach unetin.

matcneq, npaue
#tpu b o bo th ale not

in an unauy
hent elemen

and ttil fue-


<KP 2
Repeat with
As LOmpaled
talgt elmn
ast clemN in an. aiua
Stcp 6 tue (ast ctemn doeU Matc
tue lieal search uuity n

gtemunt noc 10und" will

diiptayt d

Bnay Search
Binay Seavch io e to ind aM m
-ent in a SOY ttd ail aiy

IE the allay w t 0 r t , ou u t
SOYt it uring a tov tiug ttehinme
a mge oY

Atovit
Step1 peet tne mjddle eleminnt
anay.0
nspeet t
oy an ailay
0 re M
tpi (nspeet tm niddte elmand
an
ala4 o weN( ana

SOon ni touWel bound beton


eotc than uppe boun
t s tmpies K. Log N

You might also like