Professional Documents
Culture Documents
Function
Day-14
By
Saurabh Shukla
( My Sir a)
?
Function is block code which has
of some
•
a ,
function Name C)
}
{
Function
Definition
}
Functions
•
Even in the sm# program ,
there is
at least one function .
• No keyword is function
•
05 calls main CI function to begin
execution of program
Functions are of two types
Userdefinedfundnsvyit
① Predefined Functions scan FC ) printfc )
getchc )
mauocc ,
② call OCI )
T
Maines
{
{ ue→ñ
=
€1 I
}
g ←
stored in
C-Lrry
ramwith.multiplefuncticnsmai.net
Pyg
{
act ;
b4 ;
au ;
}
a C)
"
print 7C Hello ) ;
{ "
} print to
¥
bet
{ "
Bye );
"
printtc
2
a ( );
} Hello Hello
Hello Bye
Ways to define a function
① Takes
Nothing ,
Returns
Nothing CTNRN)
② Take Returns
Something ,
Nothing CTSRN )
③ Return
Takes
Nothing ,
something a- NRF
④ Return
Something
Take
Something , FSRD
include
stdio.tn?TNRNvoidaddC1i-
# <
Type
t.dt.cl?&-a,&b);C--a-b;printfC'
scant ( "
%d c) ;
' "
sum is ,
RN
11 No return keyword means
} (Returns
Nothing )
TSRN
# include < stdionh >
{ int × , Y ; "
numbers ) :
printff
"
Enter two
scan 7C t.dt.cl
" "
,
& × ,& y ) ;
-
{
into ;
c- atb ;
%d !
_
"
is c) ;
print 7C sum
}
# include < stdio.tn> TNPˢ
return
intaddc ) ; ① it returns value
int Maine ) ② it returns control
{ int s ;
we cannot return
5- add C) ; more than one
printfdsumisy.cl?s);uaheusmyretnm
return 0
; keyword .
}
int add C)
{ inta bei
,
"
two numbers ) ;
printfc
"
Enter
C=a+b ;
return c;
}
TSRS
#include < station h> -
t.cl/-d'',&-x,&-Y)is--addC#yy);prirtFC
scan 7- (
"
"
sum is XD "is ) ;
return 0 ;
}
int add Cinta ,
int b)
{ int e ;
C = a +b ;
return C ;