제 4 장 함수와 기억 클래스

  • Published on
    17-Mar-2016

  • View
    35

  • Download
    6

Embed Size (px)

DESCRIPTION

4 . (contd). (argument) (main) (modularity) . . . . - PowerPoint PPT Presentation

Transcript

<ul><li><p> 4 </p></li><li><p> (contd) (argument) (main) (modularity) </p></li><li><p> printf(), scanf(), getch() reference guide #include ex) math.h : graphics.h : string.h : </p></li><li><p> return-type fuction-name(argument declarations){declarations and statements}</p></li><li><p> void return ; C int (prototype) </p></li><li><p> (prototype) </p></li><li><p> return-type function-name(argument list); void </p></li><li><p> double sqrt(double x);double atof(char []);int getchar(void);</p></li><li><p>#include float max(float a, float b, float c);</p><p>main(){float x,y,z,k;printf(":"); scanf("%f %f %f", &amp;x, &amp;y, &amp;z); k = max(x, y, z); printf(": %f\n",k); }</p></li><li><p> (cond)float max(float a, float b, float c){float mx; if (a &gt; b) mx = a; else mx = b;if (c &gt; mx) mx = c;return(mx);}</p></li><li><p> Call by value , .Call by reference , . </p></li><li><p> #include </p><p>void inc_bad(int a) {a += 1;}</p><p>void inc_good(int *a) {*a += 1;}</p></li><li><p> (cond)void main(void) {int i = 5, j = 10;int *p;p = &amp;j;</p><p>printf("%d %d %d",inc_bad(i),inc_good(&amp;j),inc_good(p));}inc_bad(i) call by valueinc_good(&amp;j) inc_good(p) call by reference</p></li><li><p>Recursion (recursion) (, ) </p></li><li>Recursion #include long fact(int n) {if(n </li><li><p>main main() int main( int argc, char *agrv[], char *env[] ) ;int argc : command line char *argv[] : command line .argv[0] : ( )argv[1] : white character(space tab) </p></li><li><p>C (preprocessor)(preprocessor) : #include : #define : #if, #else, #endif, #ifdef, #ifndef #include "filename" #include "filename" </p></li><li><p> #define #define name replacement textreplacement text \ name replacement text #define #define max(A, B)((A) &gt; (B) ? (A) : (B))</p></li><li><p> (scope) . (local variable, ) ({} ) (, automatic variable)</p></li><li><p> (global variable, ) </p></li><li><p> ex) int extvar ; /* */ char extarray[100] ; /* */ extern int extvar ; /*, extvar */ extern char extarray[100] ; /**/ </p></li><li><p> (static variable) ex) static int c ;register CPU : performaceint unsigned int </p></li><li><p> (static )#include void test(){static int s_count = 0;int a_count = 0;</p><p>s_count++;a_count++;printf("static count = %dcount = %d",s_count,a_count);}main(){int I;for(i=1; i</p></li><li> (Factorial)#include double fact(); /* */ main(){ int n = 0; /* */do { printf(" :");scanf("%d",&amp;n); if (n</li><li><p>(cond)</p><p>double fact( int k ){ register int i; /* */double s = 1; for (i = 1;i </p></li></ul>