吴裕雄--天生自然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 = ;
int b = ;
int ret; /* 调用函数来获取最大值 */
ret = max(a, b); printf( "Max value is : %d\n", ret ); return ;
} /* 函数返回两个数中较大的那个数 */
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 = ;
int b = ; printf("交换前,a 的值: %d\n", a );
printf("交换前,b 的值: %d\n", b ); /* 调用函数来交换值 */
swap(a, b); printf("交换后,a 的值: %d\n", a );
printf("交换后,b 的值: %d\n", b ); return ;
}
/* 函数定义 */
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 = ;
int b = ; printf("交换前,a 的值: %d\n", a );
printf("交换前,b 的值: %d\n", b ); /* 调用函数来交换值
* &a 表示指向 a 的指针,即变量 a 的地址
* &b 表示指向 b 的指针,即变量 b 的地址
*/
swap(&a, &b); printf("交换后,a 的值: %d\n", a );
printf("交换后,b 的值: %d\n", b ); return ;
}
吴裕雄--天生自然C语言开发:函数的更多相关文章
- 吴裕雄--天生自然C语言开发:函数指针
#include <stdio.h> int max(int x, int y) { return x > y ? x : y; } int main(void) { /* p 是函 ...
- 吴裕雄--天生自然 R语言开发学习:R语言的安装与配置
下载R语言和开发工具RStudio安装包 先安装R
- 吴裕雄--天生自然C语言开发:结构体
struct tag { member-list member-list member-list ... } variable-list ; struct Books { ]; ]; ]; int b ...
- 吴裕雄--天生自然 R语言开发学习:数据集和数据结构
数据集的概念 数据集通常是由数据构成的一个矩形数组,行表示观测,列表示变量.表2-1提供了一个假想的病例数据集. 不同的行业对于数据集的行和列叫法不同.统计学家称它们为观测(observation)和 ...
- 吴裕雄--天生自然C语言开发:指针
#include <stdio.h> int main () { int var1; ]; printf("var1 变量的地址: %p\n", &var1 ) ...
- 吴裕雄--天生自然C语言开发:数组
] = {1000.0, 2.0, 3.4, 7.0, 50.0}; ]; #include <stdio.h> int main () { ]; /* n 是一个包含 10 个整数的数组 ...
- 吴裕雄--天生自然C语言开发:作用域规则
#include <stdio.h> int main () { /* 局部变量声明 */ int a, b; int c; /* 实际初始化 */ a = ; b = ; c = a + ...
- 吴裕雄--天生自然C语言开发:存储类
{ int mount; auto int month; } { register int miles; } #include <stdio.h> /* 函数声明 */ void func ...
- 吴裕雄--天生自然C语言开发:数据类型
#include <stdio.h> #include <limits.h> int main() { printf("int 存储大小 : %lu \n" ...
随机推荐
- ArrayList源码阅读笔记
ArrayList ArrayList继承自AbstractList抽象类,实现了RandomAccess, Cloneable, java.io.Serializable接口,其中RandomAcc ...
- Codeforces 1291A - Even But Not Even
题目大意: 给定一个字符串数字(很大) 问能不能删除一些数字(或者不删除) 使得剩余的数字各位数相加是偶数,但是这整个数字是个奇数 解题思路: 统计字符串中单个数字奇数的个数 分情况 个数为0或者1时 ...
- Mybatis实现增删改查(二)
1. 准备 请先完成Mybatis基本配置(一)的基本内容 2. 查询多条商品信息 1)在com.mybatis.dao.PartDao中增加接口函数 public List<PartInfo& ...
- hook键盘钩子_非dll
unit Unit1; // download by http://www.codefans.net interface uses Windows, Messages, SysUtils, Class ...
- Linux--Centos7开启关闭端口
参考 http://blog.csdn.net/u013410747/article/details/61696178 查看已开放的端口(默认不开放任何端口) firewall-cmd --li ...
- python 2.7编译安装
一 官网下载python2.7源码: python安装pip python -m ensurepip --default-pip
- 转:以下是目前已经建立的sub一览 来自:https://zhuanlan.zhihu.com/p/91935757
转:以下是目前已经建立的sub一览 来自:https://zhuanlan.zhihu.com/p/91935757 作者: Lorgar 理工科 科学(和英文r/science一样,只接受论文讨论 ...
- 17.3.12--urllib2模块
1---urllib2是非常强大的Python网络资源访问模块,它的功能和urllib模块相似 python标准库中的urllib2模块可以说是urlib模块的一个升级的复杂版,不需要另外下载, 比如 ...
- PAT Advanced 1078 Hashing (25) [Hash ⼆次⽅探查法]
题目 The task of this problem is simple: insert a sequence of distinct positive integers into a hash t ...
- 使用flask_sqlalchemy操作mysql的一个测试
示例代码 from flask_sqlalchemy import SQLAlchemy from flask import Flask app=Flask(__name__) app.config[ ...