SlideShare una empresa de Scribd logo
1 de 21
S r i ma n
    Sa wa r t h i a
     Cl a s s : XI
     c o mme r c e
    R o l l n o : 25
1
•A l a r g en p r r o o d a m i s
             I   t      g r u c
  b r o k e n i n ti oo s m a l l e r
                 t        n
  u n i t s k n o wn a s
  f u n c t i o n s
  •A f u n c t i o n i s a
  s u b p r o g r a m t h a t a c t s
  o n d a t a a n d o f t e n
  r e t u r n s a v a l u e
  •F u n c t i o n m a k e s
  p r o g r a m h a n d l i n g
  e a s i e r .
  •F u n c t i o n m a k e a
2 p r o g r a m r e a d a b l e ,
•A pF u n c a m o r i t t e n
           r o g r t i wn
    w i t Sht n u m esr to iu s
               a t i
    f u n c t i c s s i s e a s i e r t o
                  o n
    ma i n t a i n , u p d a t e a n d
    d e b u g a l o n g p r o g r a m.
    •T h e m a i n () f u n c t i o n
    s h o u l d b e v e r y s h o r t
    a n d s h o u l d c o n s i s t o f
    f u n c t i o n a l c a l l s .
    •A f u n c t i o n r e t u r n s
    b a c k a c a l l i n g c o d e .
    •A f t e r t h e c a l l o f t h e
    s t a t e me n t t h e p r o g r a m
    r e a c h e s b a c k t o ma i n .
3   •L e t s l o o k a t a n
:
     void main()
    {
             statement 1;
             statement 2;
             statement 3;
             *function1();
             statement 4;
             statement 5;
             *function2();
             Now function 2 will be executed
             statement 6;
             Back to main()
    }

    * They are function calls



4
a r   e p a r t o f
      c o   mp i l e r p a c k a    g e .
      Th    e s e a r e p a r t     o f
      s t   a n d a r d l i b r a   r y
      ma    d e a v a i l a b l e    b y
      c o   mp i l e r .

    2. U s e r d e f i n e d
      f u n c t i o n s : Th e u s e r
      d e f i n e d f u n c t i o n s
      a r e c r e a t e d a s p e r
      r e q u i r Tey m ee ns t s o f
                      p
      t h e p r o go r f a m m e r .
                  Fu n c t
5
                   i o n s
Fu n c t i o n
    D e •Tfuh seit f bu en cdi te if toi nnie d o n
        m
                      n
            b e f o r e t h e u s e o f
            a f u n c t i o n

            •T h e g e n e r a l     f o r m
            o f f u n c t i o n
            d e f i n i t i o n

            t y p e f u n c t i o n
            n a m e (p a r a m e t e r
            l i s t )
                   {
                   b o d y o f t h e
            f u n c t i o n
                   }

6
Fu n c t i o n
    Pr o t o t y p e




7
Ne e d F o r
        Pr o t o t y p
              e

    •F u n c t i o n p r o t o t y p i n g
    e n a b l e s a c o mp i l e r t o
    c a r e f u l l y c o mp a r e e a c h
    u s e o f t h e f u n c t i o n wi t h
    t h e p r o t o t y p e t o
    d e t e r mi n e w h e t h e r t h e
    f u n c t i o n i s i n v o k e d
    p r o p e r l y .
    •C ++ m a k e s t h e f u n c t i o n
    p r o t o t y p i n g e s s e n t i a l .
    •F l o a t a r e a (f l o a t a ,
8
    f l o a t )
Us e o f            v o i d

      Vo i d       d a t a t y p e s t h a t i t
       s   p   e c i f i e s a n e mp t y s e t
       o   f    v a l u e s a n d i t i s u s e d
       a   s    t h e r e t u r n t y p e o f
       f   u   n c t i o n s t h a t d o n o t
       r   e   t u r n a v a l u e
      I   f    a f u n c t i o n d o n o t
       r   e   t u r n a r e s u l t d e c l a r e
       t   h   e r e s u l t t y p e a s v o i d
      I   f    a f u n c t i o n t a k e s n o
9
       a   r   g u me n t s , y o u s h o u l d
A F UNCT I ON
  P ROT OT Y P E
  I S NOT
  N E E D E D WH E N
  T HE
  F UNCT I ON
10DE F I NI T I ON
F u n c t i o n d e f i n i t i o n v /s
     f u n c t i o n p r o t o t y p e



      Fu n c t i o n p r o t o t y p e
      i n t s u m (i n t n 1, i n t n 2);

  F u n c t i o n       d e f i n i t i o n
      i n t    s u m (i n t a , i n t b )
      {   i   n t s ;
          s   =a +b ;
          r   e t u r n s ;
      }

11
Re t u r n i n g f r o m
     a f u n c t i o n

      T h e  R e t u r n s t a t e me n t
       t h e r e t u r n s t a t e me n t    i s
       u s e f u l i n t wo wa y s
      I mme d i a t e e x i t f r o m
       f u n c t i o n
      Re t u r n a v a l u e f r o m
       c a l l i n g c o d e



12
Re t u r n i n g
     v a l u e s


      Al l       f u n c t i o n e x c e p t
       t   h   o s e o f t y p e v o i d
       r   e   t u r n a v a l u e
      T   h   i s v a l u e i s s p e c i f i e d
       b   y    j u mp s t a t e me n t s
      I   f    a f u n c t i o n l a c k s a
       r   e   t u r n e d v a l u e a
       f   u   n c t i o n i s t e c h n i c a l l y
       u   n   d e f i n e d
13
C o mp u t a t i o n a l
     Fu n c t i o n s


      T h e      f u n c t i   o n t h a t
       c   a   l c u l a t e    o r c o mp u t e
       s   o   me v a l u e      a n d r e t u r n
       t   h   e c o mp u t     e d v a l u e
      E   x   a mp l e s q     r t (),p o w (),c o s .




14
 T h e    f u n c t i o n s t h a t
       ma    n i p u l a t e i n f o r ma t i o n
       a n   d r e t u r n a s u c c e s s o r
       f a   i l u r e c o d e
      Ex    a mp l e i f a c o n d i t i o n
       i s    t r u e r e t u r n 0
       e l   s e r e t u r n 1.




15
Pr o c e d u r a l
      f u n c t i o n s

      T h e        f u n c t i o n s t h a t
       p   e   r   f o r m a n a c t i o n a n d
       h   a   v   e n o e x p l i c i t r e t u r n
       v   a   l   u e
      E   x   a   m p l e e x i t ()




16
Re t u r n i n g n o n
     i n t v a l u e s
        Wh    e n t h e t y p e o f
        f u   n c t i o n i s n o t
        d e   c l a r e d i t i s
        a s   s u me d a s i n t .
        Fo    r a l l n o n i n t
        r e   t u r n i n g v a l u e s
        t h   e d a t a t y p e
        s p   e c i f i e r mu s t b e
        g i   v e r
        Fo    r e x a mp l e f l o a t
        s u   m (f l o a t a , i n t b )

17
Re t u r n i n g b y
     r e f e r e n c e
      A r e f e r e n c e  i s a n a d d r e s s
       o f a f u n c t i o n .
      T a k e a e x a mp l e
     I n t & s u m (s u m &a , s u m &b )
     {     i f (a <b )
                 r e t u r n a ;
           e l s e
                 r e t u r n b ;
     }
      I n t h e a b o v e f u n c t i o n
       r e t u r n a wi l l r e t u r n t h e
18
       a d d r e s s wh e r e t h e v a l u e o f
       a h a s b e e n s t o r e d .
 A s c o p e        r u l e s o f a
      l   a   n   g u a g e a r e t h e r u l e s
      t   h   a   t d e c i d e , i n wh i c h
      p   a   r   t s o f t h e p r o g r a m a
      p   i   e   c e o f c o d e o r d a t a
      i   t   e   m wo u l d b e k n o wn a n d
      c   a   n    b e a c c e s s e d t h e r e i n .




19
L o   c   a   l s c o p e   Ki n d s
     Fu    n   c   t i o n
     s c   o   p   e                o f
     Fi    l   e    s c o p e    s c o p e
     Cl    a   s   s s c o p e


20
T HE
     END
21

Más contenido relacionado

La actualidad más candente

US Persons investments in Indian Mutual Funds are treated as PFIC's.
US Persons investments in Indian Mutual Funds are treated as PFIC's.US Persons investments in Indian Mutual Funds are treated as PFIC's.
US Persons investments in Indian Mutual Funds are treated as PFIC's.NS Global
 
5,sm,nurul ihsani,hapzi ali,tipe strategi form dan implementasi, universita m...
5,sm,nurul ihsani,hapzi ali,tipe strategi form dan implementasi, universita m...5,sm,nurul ihsani,hapzi ali,tipe strategi form dan implementasi, universita m...
5,sm,nurul ihsani,hapzi ali,tipe strategi form dan implementasi, universita m...Nurul ihsani
 
MIDI DAW II Class 11
MIDI DAW II Class 11MIDI DAW II Class 11
MIDI DAW II Class 11Walt Ribeiro
 
Securities Based Credit Lines and Loans
Securities Based Credit Lines and LoansSecurities Based Credit Lines and Loans
Securities Based Credit Lines and Loanseasysba
 
More or Less - Practicing Medicine in 2013: What's Out and What's Here to Stay
More or Less - Practicing Medicine in 2013: What's Out and What's Here to StayMore or Less - Practicing Medicine in 2013: What's Out and What's Here to Stay
More or Less - Practicing Medicine in 2013: What's Out and What's Here to StayPowerYourPractice
 
Firststepsolim 090421154659 Phpapp01
Firststepsolim 090421154659 Phpapp01Firststepsolim 090421154659 Phpapp01
Firststepsolim 090421154659 Phpapp01Jewish Agency
 
Milaap.org Employee Engagement
Milaap.org Employee EngagementMilaap.org Employee Engagement
Milaap.org Employee EngagementAnoj Viswanathan
 
Getting started with OrgSync's ePortfolio
Getting started with OrgSync's ePortfolioGetting started with OrgSync's ePortfolio
Getting started with OrgSync's ePortfolioOrgSync
 
6,sm,nurul ihsani,hapzi ali,strategic generik porter, universitas mercu buana...
6,sm,nurul ihsani,hapzi ali,strategic generik porter, universitas mercu buana...6,sm,nurul ihsani,hapzi ali,strategic generik porter, universitas mercu buana...
6,sm,nurul ihsani,hapzi ali,strategic generik porter, universitas mercu buana...Nurul ihsani
 
5 non invasive aesthetic procedures on the rise for 2018
5 non invasive aesthetic procedures on the rise for 20185 non invasive aesthetic procedures on the rise for 2018
5 non invasive aesthetic procedures on the rise for 2018Cutis Medical Laser Clinics
 
Comenius presentazione power point
Comenius presentazione power pointComenius presentazione power point
Comenius presentazione power pointViktorija Gailisa
 

La actualidad más candente (20)

US Persons investments in Indian Mutual Funds are treated as PFIC's.
US Persons investments in Indian Mutual Funds are treated as PFIC's.US Persons investments in Indian Mutual Funds are treated as PFIC's.
US Persons investments in Indian Mutual Funds are treated as PFIC's.
 
Duck tutorial
Duck tutorialDuck tutorial
Duck tutorial
 
5,sm,nurul ihsani,hapzi ali,tipe strategi form dan implementasi, universita m...
5,sm,nurul ihsani,hapzi ali,tipe strategi form dan implementasi, universita m...5,sm,nurul ihsani,hapzi ali,tipe strategi form dan implementasi, universita m...
5,sm,nurul ihsani,hapzi ali,tipe strategi form dan implementasi, universita m...
 
MIDI DAW II Class 11
MIDI DAW II Class 11MIDI DAW II Class 11
MIDI DAW II Class 11
 
Deutschland-Niederlande #EURO2012
Deutschland-Niederlande #EURO2012Deutschland-Niederlande #EURO2012
Deutschland-Niederlande #EURO2012
 
20 FINE Slides: Hospitality
20 FINE Slides: Hospitality20 FINE Slides: Hospitality
20 FINE Slides: Hospitality
 
resume
resumeresume
resume
 
Cognitive perspective
Cognitive perspectiveCognitive perspective
Cognitive perspective
 
Securities Based Credit Lines and Loans
Securities Based Credit Lines and LoansSecurities Based Credit Lines and Loans
Securities Based Credit Lines and Loans
 
One sure method
One sure methodOne sure method
One sure method
 
More or Less - Practicing Medicine in 2013: What's Out and What's Here to Stay
More or Less - Practicing Medicine in 2013: What's Out and What's Here to StayMore or Less - Practicing Medicine in 2013: What's Out and What's Here to Stay
More or Less - Practicing Medicine in 2013: What's Out and What's Here to Stay
 
Firststepsolim 090421154659 Phpapp01
Firststepsolim 090421154659 Phpapp01Firststepsolim 090421154659 Phpapp01
Firststepsolim 090421154659 Phpapp01
 
Portfolio
PortfolioPortfolio
Portfolio
 
Matematika Diskrit
Matematika DiskritMatematika Diskrit
Matematika Diskrit
 
Trasteros en Vitoria - Gasteiz
Trasteros en Vitoria - GasteizTrasteros en Vitoria - Gasteiz
Trasteros en Vitoria - Gasteiz
 
Milaap.org Employee Engagement
Milaap.org Employee EngagementMilaap.org Employee Engagement
Milaap.org Employee Engagement
 
Getting started with OrgSync's ePortfolio
Getting started with OrgSync's ePortfolioGetting started with OrgSync's ePortfolio
Getting started with OrgSync's ePortfolio
 
6,sm,nurul ihsani,hapzi ali,strategic generik porter, universitas mercu buana...
6,sm,nurul ihsani,hapzi ali,strategic generik porter, universitas mercu buana...6,sm,nurul ihsani,hapzi ali,strategic generik porter, universitas mercu buana...
6,sm,nurul ihsani,hapzi ali,strategic generik porter, universitas mercu buana...
 
5 non invasive aesthetic procedures on the rise for 2018
5 non invasive aesthetic procedures on the rise for 20185 non invasive aesthetic procedures on the rise for 2018
5 non invasive aesthetic procedures on the rise for 2018
 
Comenius presentazione power point
Comenius presentazione power pointComenius presentazione power point
Comenius presentazione power point
 

Destacado (18)

Lesson plan1
Lesson plan1Lesson plan1
Lesson plan1
 
Lesson plan1
Lesson plan1Lesson plan1
Lesson plan1
 
Oovoo
OovooOovoo
Oovoo
 
Love to tell
Love to tellLove to tell
Love to tell
 
Oovoo
OovooOovoo
Oovoo
 
Professional goal walden
Professional goal waldenProfessional goal walden
Professional goal walden
 
Trabalho final
Trabalho finalTrabalho final
Trabalho final
 
Oovoo
OovooOovoo
Oovoo
 
Pharmacology bao jiaolin
Pharmacology bao jiaolinPharmacology bao jiaolin
Pharmacology bao jiaolin
 
Presentationforenglish2
Presentationforenglish2Presentationforenglish2
Presentationforenglish2
 
Jeopardy government 1
Jeopardy   government 1Jeopardy   government 1
Jeopardy government 1
 
Lesson plan
Lesson planLesson plan
Lesson plan
 
Sriman
SrimanSriman
Sriman
 
Professional goal walden
Professional goal waldenProfessional goal walden
Professional goal walden
 
Film315 Presentation (Cwitzel)
Film315 Presentation (Cwitzel)Film315 Presentation (Cwitzel)
Film315 Presentation (Cwitzel)
 
International business
International businessInternational business
International business
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
 
Suku Kata Terbuka
Suku Kata TerbukaSuku Kata Terbuka
Suku Kata Terbuka
 

Functions

  • 1. S r i ma n Sa wa r t h i a Cl a s s : XI c o mme r c e R o l l n o : 25 1
  • 2. •A l a r g en p r r o o d a m i s I t g r u c b r o k e n i n ti oo s m a l l e r t n u n i t s k n o wn a s f u n c t i o n s •A f u n c t i o n i s a s u b p r o g r a m t h a t a c t s o n d a t a a n d o f t e n r e t u r n s a v a l u e •F u n c t i o n m a k e s p r o g r a m h a n d l i n g e a s i e r . •F u n c t i o n m a k e a 2 p r o g r a m r e a d a b l e ,
  • 3. •A pF u n c a m o r i t t e n r o g r t i wn w i t Sht n u m esr to iu s a t i f u n c t i c s s i s e a s i e r t o o n ma i n t a i n , u p d a t e a n d d e b u g a l o n g p r o g r a m. •T h e m a i n () f u n c t i o n s h o u l d b e v e r y s h o r t a n d s h o u l d c o n s i s t o f f u n c t i o n a l c a l l s . •A f u n c t i o n r e t u r n s b a c k a c a l l i n g c o d e . •A f t e r t h e c a l l o f t h e s t a t e me n t t h e p r o g r a m r e a c h e s b a c k t o ma i n . 3 •L e t s l o o k a t a n
  • 4. : void main() { statement 1; statement 2; statement 3; *function1(); statement 4; statement 5; *function2(); Now function 2 will be executed statement 6; Back to main() } * They are function calls 4
  • 5. a r e p a r t o f c o mp i l e r p a c k a g e . Th e s e a r e p a r t o f s t a n d a r d l i b r a r y ma d e a v a i l a b l e b y c o mp i l e r . 2. U s e r d e f i n e d f u n c t i o n s : Th e u s e r d e f i n e d f u n c t i o n s a r e c r e a t e d a s p e r r e q u i r Tey m ee ns t s o f p t h e p r o go r f a m m e r . Fu n c t 5 i o n s
  • 6. Fu n c t i o n D e •Tfuh seit f bu en cdi te if toi nnie d o n m n b e f o r e t h e u s e o f a f u n c t i o n •T h e g e n e r a l f o r m o f f u n c t i o n d e f i n i t i o n t y p e f u n c t i o n n a m e (p a r a m e t e r l i s t ) { b o d y o f t h e f u n c t i o n } 6
  • 7. Fu n c t i o n Pr o t o t y p e 7
  • 8. Ne e d F o r Pr o t o t y p e •F u n c t i o n p r o t o t y p i n g e n a b l e s a c o mp i l e r t o c a r e f u l l y c o mp a r e e a c h u s e o f t h e f u n c t i o n wi t h t h e p r o t o t y p e t o d e t e r mi n e w h e t h e r t h e f u n c t i o n i s i n v o k e d p r o p e r l y . •C ++ m a k e s t h e f u n c t i o n p r o t o t y p i n g e s s e n t i a l . •F l o a t a r e a (f l o a t a , 8 f l o a t )
  • 9. Us e o f v o i d  Vo i d d a t a t y p e s t h a t i t s p e c i f i e s a n e mp t y s e t o f v a l u e s a n d i t i s u s e d a s t h e r e t u r n t y p e o f f u n c t i o n s t h a t d o n o t r e t u r n a v a l u e  I f a f u n c t i o n d o n o t r e t u r n a r e s u l t d e c l a r e t h e r e s u l t t y p e a s v o i d  I f a f u n c t i o n t a k e s n o 9 a r g u me n t s , y o u s h o u l d
  • 10. A F UNCT I ON P ROT OT Y P E I S NOT N E E D E D WH E N T HE F UNCT I ON 10DE F I NI T I ON
  • 11. F u n c t i o n d e f i n i t i o n v /s f u n c t i o n p r o t o t y p e Fu n c t i o n p r o t o t y p e i n t s u m (i n t n 1, i n t n 2);  F u n c t i o n d e f i n i t i o n i n t s u m (i n t a , i n t b ) { i n t s ; s =a +b ; r e t u r n s ; } 11
  • 12. Re t u r n i n g f r o m a f u n c t i o n  T h e R e t u r n s t a t e me n t t h e r e t u r n s t a t e me n t i s u s e f u l i n t wo wa y s  I mme d i a t e e x i t f r o m f u n c t i o n  Re t u r n a v a l u e f r o m c a l l i n g c o d e 12
  • 13. Re t u r n i n g v a l u e s  Al l f u n c t i o n e x c e p t t h o s e o f t y p e v o i d r e t u r n a v a l u e  T h i s v a l u e i s s p e c i f i e d b y j u mp s t a t e me n t s  I f a f u n c t i o n l a c k s a r e t u r n e d v a l u e a f u n c t i o n i s t e c h n i c a l l y u n d e f i n e d 13
  • 14. C o mp u t a t i o n a l Fu n c t i o n s  T h e f u n c t i o n t h a t c a l c u l a t e o r c o mp u t e s o me v a l u e a n d r e t u r n t h e c o mp u t e d v a l u e  E x a mp l e s q r t (),p o w (),c o s . 14
  • 15.  T h e f u n c t i o n s t h a t ma n i p u l a t e i n f o r ma t i o n a n d r e t u r n a s u c c e s s o r f a i l u r e c o d e  Ex a mp l e i f a c o n d i t i o n i s t r u e r e t u r n 0 e l s e r e t u r n 1. 15
  • 16. Pr o c e d u r a l f u n c t i o n s  T h e f u n c t i o n s t h a t p e r f o r m a n a c t i o n a n d h a v e n o e x p l i c i t r e t u r n v a l u e  E x a m p l e e x i t () 16
  • 17. Re t u r n i n g n o n i n t v a l u e s Wh e n t h e t y p e o f f u n c t i o n i s n o t d e c l a r e d i t i s a s s u me d a s i n t . Fo r a l l n o n i n t r e t u r n i n g v a l u e s t h e d a t a t y p e s p e c i f i e r mu s t b e g i v e r Fo r e x a mp l e f l o a t s u m (f l o a t a , i n t b ) 17
  • 18. Re t u r n i n g b y r e f e r e n c e  A r e f e r e n c e i s a n a d d r e s s o f a f u n c t i o n .  T a k e a e x a mp l e I n t & s u m (s u m &a , s u m &b ) { i f (a <b ) r e t u r n a ; e l s e r e t u r n b ; }  I n t h e a b o v e f u n c t i o n r e t u r n a wi l l r e t u r n t h e 18 a d d r e s s wh e r e t h e v a l u e o f a h a s b e e n s t o r e d .
  • 19.  A s c o p e r u l e s o f a l a n g u a g e a r e t h e r u l e s t h a t d e c i d e , i n wh i c h p a r t s o f t h e p r o g r a m a p i e c e o f c o d e o r d a t a i t e m wo u l d b e k n o wn a n d c a n b e a c c e s s e d t h e r e i n . 19
  • 20. L o c a l s c o p e Ki n d s Fu n c t i o n s c o p e o f Fi l e s c o p e s c o p e Cl a s s s c o p e 20
  • 21. T HE END 21