??(Function)??? - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

??(Function)???

Description:

Title: (Array) Author: pp Last modified by: penguin Created Date: 2/19/2002 4:31:55 PM Document presentation format: Company – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 19
Provided by: pp690
Category:
Tags: function

less

Transcript and Presenter's Notes

Title: ??(Function)???


1
Introduction to the C Programming Language
  • ??(Function)???

2
Fucntion
  • (?????????)

3
??Function (??)?
  • ????(Function)?
  • ???????????,??coding ??
  • ?????????,??????
  • ?????????????,?????????
  • ?????????,???????????function, ?????????????
  • ??????????(???,??????)
  • ????
  • ??????,????????
  • ???????,?????????

4
???????
  • ?????????
  • /?????main()???, ??????, ????/
  • ????? function_name (????1,????2)

5
Function????(1/2)
  • ????
  • ??????? ????(??????? ????, ??????? ???? )
  • statements /????/
  • return ??? /??????/

6
Function????(2/2)
  • ????1 (????)
  • void function_name (???? ??1,???? ??2)
  • parameters declarations /??????/
  • statements /????/
  • ????2 (???)
  • ???? function_name (???? ??1,???? ??2)
  • parameters declarations /??????/
  • statements /????/
  • return ???

7
Example 1a
  • ??????,????
  • includeltstdio.hgt
  • void p(char sn ) /????,????void?????,????ch
    ar??/
  • int main(void) /???/
  • char num10
  • printf("?????")
  • scanf("s",num)
  • p(num) /??p??/
  • printf("\n")
  • system("pause")
  • void p(char sn ) /p??/
  • printf("\n\n????? s",sn)

?????
?????
8
Example 1b
  • ??????,????
  • includeltstdio.hgt
  • void p(char ) /????,????void?????,????char??
    /
  • int main(void) /???/
  • char num10
  • printf("?????")
  • scanf("s",num)
  • p(num) /??p??/
  • printf("\n")
  • system("pause")
  • void p(char num )
  • printf("\n\n????? s",num)

/p???num ??????num ????/
9
Example 2
?? ?????,???????,?????????????,????. include
ltstdio.hgt int add(int,int)                      
     /????,???? int???int??,????int?? / void
show(int)                         
/????,???? void?????,????int?? /  void main()
int nNum1 5 , nNum2 5 , nSum
nSum add(nNum1,nNum2)       /?add(nNum1,nNum2)
?return??nSum / show(nSum)                  
               /?nSum??show?? /    
/?????nNum1,nNum2,????int?nData1 nNum1, nNum2
nData2 /  int add(int nData1,int
nData2)        return (nData1
nData2)        /??nData1 nData2???? /
  /????nSum,????int nData,?nData nSum
/  void show(int nData) printf("The Anser
is d" , nData)
10
??????????
  • ?????
  • ?????

11
Function????
  • ??????????????.
  • ????????,?????.
  • ????????????.
  • ?????????????????????????, ?????????,???????,
    ????????.
  • ?????????, ????????????,????? return (???)
  • return ????
  • ???????,????????
  • return ????????????????,?????????, ?????????.

12
???
  • return() ???????
  • ???????????
  • ?return()??????????????????

13
??
14
???????
  • ?????(Global variable) ????????????,
    ???????????????.
  • ?????(Local variable) ??????????????????,
    ???????????. ?????????????, ?????????????.

includeltstdio.hgt /????,?????/ ???? ????
/????/ int main( ) ???? /????/ return
0 /???/
15
???????
  • C????????? auto, extern, static, register
  • ????auto ?????????????.
  • ????(Static variable) ????????, ??????????,
    ???????????????????.
  • ????(Extern variable) ???????????????????????,
    ???????.
  • ?????? ????????????????, ??????????????.
  • ?????(Register variable)???????????, ???????2?,
    ???2?, ??????????????auto????.

16
??? ?????????
includeltstdio.hgt includeltstdlib.hgt int
sum(void) void main(void) int i /????/
for (i1 ilt3 i) printf("dth time
d \n", i, sum()) system("pause")
int sum(void) int x0 /????/ x
return(x)
17
??? ?????????
includeltstdio.hgt includeltstdlib.hgt void main()
int sum(void) int i /????/ for
(i1 ilt3 i) printf("dth time d \n",
i, sum()) system("pause") int sum(void)
static int x0 x return(x)
18
??? ?????????
includeltstdio.hgt includeltstdlib.hgt int
sum(void) int x0 /????/ void main(void)
int i /????/ x for (i1 ilt3
i) printf("dth time d \n", i,
sum()) system("pause") int
sum(void) x return(x)
Write a Comment
User Comments (0)
About PowerShow.com