吴裕雄--天生自然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" ...
随机推荐
- SAP_SD常用事务代码
1.创建/修改/显示销售订单:VA01/VA02/VA03 2.根据销售订单创建交货单:VL01N 3.修改/显示交货单:VL02N/VL03N 4.交货单发货过账:VL02N 5.发货过账冲销:VL ...
- 使用websocket实现单聊和多聊
单聊: 前端: <!DOCTYPE html> <html lang="zh-CN"> <head> <meta http-equiv=& ...
- 工程日记之ChildLost(1):URLSession
URLSession 是什么 URL Loading System提供了访问URL资源的系统,提供了访问http/https/自定义URL访问的接口.其中,URLSession实例可以创建多个URLS ...
- Java模板引擎之Freemarker 学习笔记 一
什么是Freemarker Freemarker是模板引擎,不是Web框架,只是视图层的组件,官网是 https://freemarker.apache.org/ Freemarker原理 数据模型+ ...
- 吴裕雄--天生自然 PHP开发学习:数组
<?php $cars=array("Volvo","BMW","Toyota"); echo "I like " ...
- 第二季第六天 part2 css动画
transition:background 2s,width 3s(第二个参数为变化时间) 1s(第三个参数为延迟时间): class:hover {} 伪类,鼠标移上去一个变化 <img ...
- Qt在vs2010下的配置
https://blog.csdn.net/chenbang110/article/details/7607250 首先不要使用中文目录, 1 下载Qt的安装包和VS2010的Qt插件 2. 安装Qt ...
- Linux-让程序不能多次运行
1.因为守护进程是长时间运行而不退出的,因此./a.out执行一次就有一个进程,执行多次就有多个进程. 2.这样并不是我们想要的.我们的守护进程一般都是服务器,服务器程序只要运行一个就够了,多次同时运 ...
- http head详解
Http普通报头: 少数报头域用于所有的请求和响应消息, 但并不用于被传输的实体 cache-Control: 用于指定缓存指令, 缓存指令是单向的 ,且是独立的(一个消息的缓存指令不会影 ...
- windows下python自带的pip安装速度过慢解决方案
自带下载地址为国外源下载速度时常在20KB以内切换为国内源直接满速! 国内源: 新版ubuntu要求使用https源,要注意. 清华:https://pypi.tuna.tsinghua.edu.cn ...