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;
    }
  • 相关阅读:
    ajax GET 传输中文乱码
    php 验证码 图像存在错误 无法显示 解决方法
    ajax 简单实例
    PHP continue break 区别 用法
    php注意事项
    php7注意事项
    腾讯2015后台模拟题
    【leetcode】_3Sum
    最小的k个数 2.5
    《Hadoop权威指南》笔记 第三章 并行复制及存档
  • 原文地址:https://www.cnblogs.com/tszr/p/10968294.html
Copyright © 2011-2022 走看看