You are on page 1of 10

C Language LIVE Community Classes

Function

Day-14

By
Saurabh Shukla
( My Sir a)
?
Function is block code which has
of some

a ,

name for identification .

function Name C)

}
{
Function
Definition

}
Functions

Even in the sm# program ,
there is
at least one function .

All function names must be unique



One function name must be main C)

You can define functions in


any sequence .

• 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-
# <

int Maine ) function declaration


{ Function call
addc ) ; ←
return 0 ;
}
void add C) I/ Empty parenthesis means TN
↑ { (takes
Nothing)
intact , c ;
Return "
);
Enter two number"s
Printfc
"

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 >

void add ( int , int ) ;


int main C)

{ int × , Y ; "
numbers ) :
printff
"
Enter two
scan 7C t.dt.cl
" "
,
& × ,& y ) ;
-

add ( x , y) ; 11 call by valve

return o # Actual arguments


}
b) a b Formal argument
void add Cinta ,
int ← ,

{
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

scanfc "%d%d " 8-a ,&b ) : ,

C=a+b ;

return c;

}
TSRS
#include < station h> -

int add ( int , int ) ;


int Maine )
{ int 2C Y S 's
, ,
"
printFC" Enter two numbers ) ?

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 ;

You might also like