You are on page 1of 17

asSmAte

Date
Page

10-Ses umbue
D
fUNCTION OINTER

Example-1

#incudesstdoh»
Mcunl)

int 1 0

funl),
w(u", fu); un adrus

pwntf ("ki"),

hi1345 3618
fu aderus

amlu -2

nclude Lstaio.hy
main)

int x10

bndf( °o " &fm),


printtu n, fn
ptdf("hi)

h 13141886
31418H8b

NoTE
8fn, both wntte in brralf ) Mans
that t is adoles o the paiulan fnetion

Q Can a fuetion setu Vau ?

)Hha in Statk memon MLMOy

Xam-5
inchae &Staio.hy
intf (void);_ Wawina Tmction
Maun) addros e doal Vadalde

int Z f ) ;
o Aen o_
brntf("ou", z)
itfou*z);
int tu(void) Adalre o_ Xwil
On Stack yaua wont
int 0;
Gwailable betaune Vatiabl dis
T
C
5Exam-5
inude <stäio.hz
int fun(void);
Man

int i, x
10 TYOY
o r 0 i5 i++) ddas ul
iiot xbi fnt times
printt(u hd,x

in
fun (vcid)
R
int 5

printtod
un (&),_

6) Exampl-6

inclule <stdio hy
ot fun (void);
Main)

int =10, *p
tor i=o, ik5;'i++)
tun)
btf (ou b. sp)
Poge

int xun void) 6


6
int : 5
6
6
pmntf ("d o", 2),
Selsn(&z); Addr o
6

1Fxaml-7
#incude <stdie.b>
int fun(void)
Tnain

Int i, a 10, *p
to (i0, ia5;i++

prntf(u 7d Je",

int fu (veid) 6

int 5;
Addros 6

6
6
t i (ed", x);
aeiun 8X), 6
6

6
Addru
8 ineude sdo
int fn[void)

mo n)

inti 10, *
ov(ioia5,144)

int unvod)
8
8totie iot x: 5; dddro
X++
1
pratf("d ", x);
Seu (&)
Addrm 10 1

) orap-1

d e stdaoh
Stotic int x:5
int fun (void);
moi

int Oi

tun )
rwdf (" u Jdp *p);
clASSMAte
Dofe
Page

int *f(votd) 6
Addres e 6 6
Addre o7 7
tt
rutf(Jod ); 8
Addres 8 8

Addro o 1
0
Addre o

Exomple-10

#incude kstdo.hy
int x-5
int fun(void)
mainD
o Same a
int i 2-i0, PrDq TaM

for (i=0) iK5i+)

funt)
prnt ( u dp.xp

int tum(veid)

brntf("d 2);
atun (3x))
C

E
poge

NvOKING A tUNCTIDON NG tuNCTION PoINTER

Examl-1

aclude <stdie .h>


maint)

intfunt) uetusn tyhe funetres


declararton
(xfptr)(),
int tALtton pointe
tn functien Pein e
Ttvfu Addrem ofuc Hen is stored
unng tttton poink
fhtr) O: invokmg func ton

int fu C)

pnntf("h");

Chi

xample- a

i r ude <stdio.h> int fnn)_


mainl
ntf(Welcerme";
int funt )
int (kfjt)(O;
fptr8fwn) ol WelLeme
3)Examu-3
include <sto.h>
main )

int funveidl)
intF t ) ) D Weleome

ptr fns
fptr (

int nO

nntf ("ielco");

4 Example -H_

#include stdio.h>
Mai n )

Void fn (flet, fleat );


Void (kpEs) (Moat,float);
ftect 65, :89
olb 6:500000
8 00 ooo

Voio fun (flect a, fload b)

f o tlo a,b);
printf"
Poge

5Exanla-5
incude kstdio hy
Recct awa (int, int);
manc) O6 T.5000o0

int lo, u: 5,
Hoat al
fRoat (kfptr)(int,int)
ptr-a
prntf Avesage =f a )

Hload Gwa (int aint b)

otetun(a+6)/a-o);
3

6 xampe-6

incuae<stduoh>
int add (int,int),
int Sub (int, int);
int mul int, int);
int uv (int, in+);
int adol inta,intb

uu(a+b);
Subint a,int b)

Sdusn a-b),
3
int (int a, int b)

Suetn (akb);

iot div(int a, int b)

Suun (alb);
3
TMain)

int fpln int,int);


int X=6, y-8; a
Chan A,
intt" Ent own ckoiceo):
Stanf ("_ 8A);_
Suwitth (h)

Cane
fptr 8add;

pihtf("Sum d",a)
boak

Cae-
fptr 8sub,
a (Pper)();
rintf Dtn .d", a);
5SMAte
Date
Page

Cane *:
fptr 8mul

print Mulply= A ,a)


b'uak;

Cane

a (*fptr) (a»y)
prin tt (Divide %d a);
break

delutt:
prott( INvauo CHoICE!");

Examp-11

ncude 4stdlo.hy
intodd int,jiot)i
int Sub (int, int)z
int mul int, int),
int v (int, int ),
int add int a, int )

aun (atb);

int Sublint a, int b)

slum (a -b);
int mulint a ,int b)

ndun (axb);
3
int dvlint a,intL)

stetuan(a/b);
3
main )

int (ipl»1)(1nt,int), (*fpEr )int,int);


int t3)int, init), GApt»4) (ind,int);_
ha ch,
pnntf (" Eiiu ou chee")
Stanf ( " , ' 8 ) ;
Switth (Ch)

Cone +':

a-(*fp)(*y)
ntf Sum .d" a)j_
break,

Cane'-';

fptr2 Swo
a(*fptr:)*)3
pruti("Dikenu Jecd " a);
bveak;
ane x':
tptr3 mu
a (*fp 3) ( z«q)
print f ( Metltpu od ", a)5.
brreak
CAne / ' :

fpr dv;
a ( f p ) (.y)
printf ("diiede e oed", a);
breau

default:
ntt ( Invabel clhote {!!");

tunCTLON PassED AS ARGUMENT To ANOTHER ungTION

le Cant eutre fction anotlwn

tion

So we Store adedresothefwchien in a uctton


DoinM. pon the tion ponka as

MeavS eutte
So, wtion poin pameo as

ucteu
tion deiuitio is pome duotlon

Syntar:
ftion nction_beinky ot agamen b)
Etre declaution e futkon- bolnlan
hould be witn A
8 xon 18
tiotlude sStdo.hy
int add (int,iot);
int (* fp) (int , int);
int patn int (+)(iot,int) int ,int)
in t ad int a, intb)

int ye= +b
dsn(Ts)

ot oheatonint (*fptr2 (int int ),int a, int b)


int Yesl pkr)(a,b),
reusn Tes)

jnt Main C)

int 18, y Sum


ptr- adol
Sun openation fptr, 2,y);_
rntf (*Sum ed J Suro);

l Sum- LO
ts/

Nvg unt tte nt nein


fuuction

ine lude <stdio.


fleat ovg (int,intD
foal (xt) (i0t,int);
float onattontloat (x) (int int) , inti)
float avq (iot ,int)

int es a4b
etun (3ussa o);

tloat ohuaton eat (tHE) (i«t.int), int


int osl fp)(a b);
eluan usl

marn )

int x8, :2,


fleat a

rintf Avesage f aw),

You might also like