next up previous contents
Next: 函式參數 Up: 函式 Previous: 定義   Contents

宣告

  1. 語法
    return_type function_name( parameter list );
    
  2. 範例
    int max(int num1, int num2);
    int max(int, int);
    
  3. 呼叫範例
    #include <stdio.h>
     
    /* function declaration */
    int max(int num1, int num2);
     
    int main ()
    {
       /* local variable definition */
       int a = 100;
       int b = 200;
       int ret;
     
       /* calling a function to get max value */
       ret = max(a, b);
     
       printf( "Max value is : %d\n", ret );
     
       return 0;
    }
     
    /* function returning the max between two numbers */
    int max(int num1, int num2) 
    {
       /* local variable declaration */
       int result;
     
       if (num1 > num2)
          result = num1;
       else
          result = num2;
     
       return result; 
    }
    



2015-01-16