15 Ways to Define Functionspdf Lyst8300 (1)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

C Language

Function

Saurabh Shukla (MySirG)


Agenda
--

① Ways to
define a function
② Header files and Library files
to
Waysdefine a function
1 . Takes
Nothing
,
Returns
Nothing
.
2 Take something ,
Returns
Nothing
.
3 Takes Nothing , Something
Return
Return something
4 . Take Something ,

a D

DA F2()
f(()
E
S int a
,
b;
printf ("d", a) ;
f2C)

Y 3
TNRN
#include Stdio h> function
I
- -
.

void add() ; function declaration


< prototype
int-
main(
Return type
E
add() ; +
(Datatype of

- value)
returned
return o ;
E call
void add (C function
& TN

I
int
Printf
a b ,C;
,
("Enter two numbers") ; function
scanf ("d % d , a &b) ; , definition
c= a +bi
(sum is % d" ) ;
printf ,

RN
No return Keyword >
-

3
#include < Stdio h > TSRN
.

void add (int , int) ;


int main()
2 int = 3, = G,
Actual
-
add (C, Y) ;
Arguments (parameters)
return o;

void add (int a ,


int b)
E &
formal Arguments
a

int c ;
c = a+ b ;
% d" C) ;
Printf /"sum is ,

3
#include Stdio n) .
INRS return
int add() ; ① value return
-

int main() a 2d /

E ② control return
int S ;
LAT

s= add) ;
yod" , s) ; You can return
printf ("sum is
only one value
return O
3
int add (

E +
in a b , 2;
,
two numbers") ;
Printf(Enter a , b) ;
scanf (" . d % d" ,

c = a +b ;
return C ;
3
#include Stdio SRS. h>

int add (int , int) ;


int main()
S 4 S ; value
in + x = 3, y= , call by
add (x y) ; ↳
s= ,

%.d" , s) ;
printf ("Sum is

return O ;

3
int add (inta ,
in+ b)
E
int ;
c = a + bi

return c;

3
predefined function
Definition of
>
- Library files

predefined function
Declaration of
Header files
>
-
auself
Ask

1 .
Function call vs Function Definition vs Function Declaration

.
2 Function saves memory

3 .
maine is a userdefined function
.

Header file Library File


↳ .
vs

When to write void ?


.
5
6 . When to write return ?
7 .
Return type of main)

8 .
call by value

.
9 Function Prototype = function declaration
10 .
Can We Call maine function (l ? yes
topmate io/mysing
.

first
-
C
second .
9

Finderested
&
add ;

in
Printf ("y d" add (3
.

,
, 4));

You might also like