l¼lomrTrJI rau,u )1eMod (_m) l!
'AfH-1_)
(i)~ µ, < jirryle;, f- )1 eihod ot
----rn€)-( <? OJ-l,l JW v fl f c, o-J.
0
f~ 0.('(l ('~ aM;na e .
f oJLomeJ-vU: - D
0 r ()){ cJ p M OJ-{. Q r-4 e__h c>l @ ---,;,.. Of<H o1Jo ,._, f ex 1,0/irn o" foJ<mJ
fo.H.o.me}c>i do nJ cha"cJ< )Ae_
'1J Ar J:ucJ Po..K o.Hcfcrt..
.1.-,.,}u1 r'L,J fr' {!c 6)
'V cJ.µ ' °t (I r.fiiJ f OJt o n1 rf.;., .
( (a \ICA ') (_( o I Ire.) [:ro mpfe : -
L') c.on bj vo.t..JC! =- C, c.++ , f~scr:JL
fl _B - ----..:..-~ n on --VQ..H p(Vf.amrTcn .
(i)
~c.E.io/ pO}(omr ~ ro.;-unal f ~
Here values of actual parameters will be copied to formal parameters and
these two different parameters store values in different locations
int X = 10, y = 20; int fun(int x, int y )
fun( x, y ); " {
printf("x = %d, y = %d", x, y ); X = 20• ,
y = 10;
Output: x = 10, y = 20
c~> ( all bj PeJe~ e. ~ /-Gel J @cJho-r c .i.A Clnd l:_rc~~~ ar~e,t:,f'
p 8
L
c)J../IJ fO j,\]u.f.
)if ~
6) Cf.n Co.ll BJ J--HtO{(!rttc.. uJC!.
&JJI ~ ~ ~~ rt'\ o d j b_ rh e..
I
Rr 1uJ fa.r{ omc ~ 'Yilic..
{j) ch,~ Me J-hG cl 0 aJJo CC4ll c._J CBj Ci< e De.,-i e n r c... •
C&. ll fu:; Qdc/J-rf/2) j Cal I bJ J ca1Jol'v
0
0 c/A c vc,J,.,, D D.r.tu.J fQH<lme~
Cun ~ c. c_hncJ c.J
f,cam pIC <;. - rR-~v,, eMC r= Qmclvt
in ( ++-
int X = 10, y = int fun(int *ptrl , int *ptr2 )
fun ( &x , &y ); {
*ptrl = 20;
*ptr2 = 10;
ptrl ptr2
1000 2000 ~B
0 ""O -h I-'•
C: "j C: ::::::s
r+ I-'• ::::::s
""O ::::::s ,,,......_ r+
C: r+ l20 X
r+ -h
,,,......_ X
© N
.. ... II
~
~~ CS> X X X
"'"'
l20 1-1
'< CS>
.............
II II
....
© 1-1 N ~ '<
~ CS>
~~ '< ...CS> ...0. II
'< '< N
CS>
... II II ....
1-1 ~
CS> 0.
...
r+ ... ...
"j
1-1
ru~ ...X
'<
..........
N
.. .
©
©
© N
I~ ......,_, ,-J-, I-'•
::::::s
r+
-h
""O ""O
* * C:
r+ r+ ::::::s
"j "j ,,,......_
N 1-1 I-'•
::::::s
II II r+
1-1 N
CS> CS> ""O *
'w. "-.
r+
"j
1-1
...
I-'•
::::::s
r+
""O *
r+
"j
N
..........
lJ.f) (all BcJ ('la ro a
A 8'---
r I ,
I ,.___~--
~,t c.i
J rCJ_H(Jrlr.ni
l ,) --Thi6 1',-6 Jep,,s f c,pdOJ-l YI eh, o cl.
(i) 0Jn< ;J c>X , o£o"- °b Co. Ii <-~l 1 fOJ-lO NrJcrl f a,J<!inJ,
pteic e d..u.Ji ~ , l,h e a r..Wo.f
r ncJ- o teie.J.
l~) rOJ1 ma.I f o.xo.rnr.lci-t ..i.J f epl 0. r <cl..
O){Cl n'l('~ ry~ C .L,,J
6 OJ ~r,wa/ fOJtornrfv.t.
fxCJ. mpl~ ~- q r, "d , ... , f o.H c.rnr.Ye>--
L--
r, Q.. n 11~ 'Void rcta1'1' C ?
po1> ~ind Yl d-·ho d i,J J.l..J'c.cf L
t .
fo~u"lv\t.t5 ~s$:"d ~~ c.. s :
~1['-'q (so 0~1(.lf- ·.
1
' J.k_,, e. IP e. -\c,I<.c.. -1-t, ~ \{af4~ °d flc.tt,,.ec I F " rvt e/c is;
~J I i: ~ /OU- IC.~ #Je. \{q( uL
.\o ~'- A ~I , ....,,&,te:,r. "
~ ""It ,1d fa k ..£ :K~ ~11 tr {Z_ef~rt!,,,e__,
'J3t<+ 1+r Nur.
1?et(J.M~~. ~ (GLI \ 'fl
R~(el'"U\C.e.. LuL rs -J,Q.~"'d'css
?& ~ ~ °1h~ ~ a /
~ ii4rtlt,-li,"t"
f1"l1iw\ fli~ \'>\ ~"l S'"
0'6 ,u I '9Z-h.co\ r~'h~ 4so
OS
~ tP) U1CJ1i,13.
I"'f "i~i'" C) /
1
(nk A [,o] ·1
ti° (1 , [f l) ;
A
J
Flow cha rt of Recursion
In the follow ing image, there is a recursive funct ion
inside which there is a recursive call that calls the
recursive funct ion until the cond ition of the probl em
is true. If the cond ition gets satisfied, then the
cond ition is false, and the progr am contr ol goes for
the rema ining state ment s and stops the program.
Recursive Function
Statem ents
TRUE
Condition
Remaining Statem ents
STOP
void recu rsiv e_fu n() // recu rsiv e f u~ 0 i ·
{
Base _cas e; // Stop ping Con ditio n
recu rsiv e_fu n(); I/ recu rsiv e call
int main ()
{
recu rsiv e_fu n(); I/ func tion call
Recursive Function
3
,,
...
,,
Void recursive_fun{)
{
2
recursive_fun() ;
} 1
int main()
{
recursive_fun() ; _ ____.
}
SCALER
foria
Advantages and Disadvantages of
Recursion
Advantages:
1. The code becomes shorter and reduces the
unnecessary calling to functions.
2. Useful for solving formula-based problems and
complex algorithms.
3. Useful in Graph and Tree traversal as they are
inherently recursive.
4. Recursion helps to divide the problem into sub-
problems and then solve them, essentially
divide and conquer.
IConclusion
• There are tw o typ es of recursion in the C
language. The firs t is Direct recursion and
Ind ire ct recursion .
• The Direct recursion in C occurs wh en a
fun cti on calls its elf dir ec tly fro m inside .
• Ind ire ct recursion occurs wh en a fun cti on calls
an oth er fun cti on , and the n tha t fun cti on calls
the firs t fun cti on again.
• The fun cti on call to its elf is a recursive call, and
the fun cti on wil l become a recursive fun cti on .
• The stack is ma int ain ed in the me mo ry to store
the recursive calls and all the variables wit h the
value passed in the m.