next up previous contents
Next: 宣告 Up: 函式 Previous: 函式   Contents

定義

  1. 語法
    return_type function_name( parameter list )
    {
       body of the function
    }
    
  2. 範例
    /* 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