zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然C语言开发:函数

    return_type function_name( parameter list )
    {
       body of the function
    }
    /* 函数返回两个数中较大的那个数 */
    int max(int num1, int num2) 
    {
       /* 局部变量声明 */
       int result;
     
       if (num1 > num2)
          result = num1;
       else
          result = num2;
     
       return result; 
    }
    #include <stdio.h>
     
    /* 函数声明 */
    int max(int num1, int num2);
     
    int main ()
    {
       /* 局部变量定义 */
       int a = 100;
       int b = 200;
       int ret;
     
       /* 调用函数来获取最大值 */
       ret = max(a, b);
     
       printf( "Max value is : %d
    ", ret );
     
       return 0;
    }
     
    /* 函数返回两个数中较大的那个数 */
    int max(int num1, int num2) 
    {
       /* 局部变量声明 */
       int result;
     
       if (num1 > num2)
          result = num1;
       else
          result = num2;
     
       return result; 
    }
    /* 函数定义 */
    void swap(int x, int y)
    {
       int temp;
    
       temp = x; /* 保存 x 的值 */
       x = y;    /* 把 y 赋值给 x */
       y = temp; /* 把 temp 赋值给 y */
      
       return;
    }
    #include <stdio.h>
     
    /* 函数声明 */
    void swap(int x, int y);
     
    int main ()
    {
       /* 局部变量定义 */
       int a = 100;
       int b = 200;
     
       printf("交换前,a 的值: %d
    ", a );
       printf("交换前,b 的值: %d
    ", b );
     
       /* 调用函数来交换值 */
       swap(a, b);
     
       printf("交换后,a 的值: %d
    ", a );
       printf("交换后,b 的值: %d
    ", b );
     
       return 0;
    }
    /* 函数定义 */
    void swap(int *x, int *y)
    {
       int temp;
       temp = *x;    /* 保存地址 x 的值 */
       *x = *y;      /* 把 y 赋值给 x */
       *y = temp;    /* 把 temp 赋值给 y */
      
       return;
    }
    #include <stdio.h>
     
    /* 函数声明 */
    void swap(int *x, int *y);
     
    int main ()
    {
       /* 局部变量定义 */
       int a = 100;
       int b = 200;
     
       printf("交换前,a 的值: %d
    ", a );
       printf("交换前,b 的值: %d
    ", b );
     
       /* 调用函数来交换值
        * &a 表示指向 a 的指针,即变量 a 的地址 
        * &b 表示指向 b 的指针,即变量 b 的地址 
       */
       swap(&a, &b);
     
       printf("交换后,a 的值: %d
    ", a );
       printf("交换后,b 的值: %d
    ", b );
     
       return 0;
    }
  • 相关阅读:
    vim命令大全
    单例的正确姿势
    mac配置android开发环境(一)
    as 开启代码混淆和自定义混淆规则
    ubuntu中使用eclipse开发android,logcat显示问题
    linux winqq 不能输入中文的解决办法
    安卓6.0之前的系统 判断app是否有录音权限
    打开一个本地apk进行安装
    (转载)单例模式的几种应用
    startActivityForResult和setResult详解
  • 原文地址:https://www.cnblogs.com/tszr/p/10968294.html
Copyright © 2011-2022 走看看