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语言开发:函数的更多相关文章

  1. 吴裕雄--天生自然C语言开发:函数指针

    #include <stdio.h> int max(int x, int y) { return x > y ? x : y; } int main(void) { /* p 是函 ...

  2. 吴裕雄--天生自然 R语言开发学习:R语言的安装与配置

    下载R语言和开发工具RStudio安装包 先安装R

  3. 吴裕雄--天生自然C语言开发:结构体

    struct tag { member-list member-list member-list ... } variable-list ; struct Books { ]; ]; ]; int b ...

  4. 吴裕雄--天生自然 R语言开发学习:数据集和数据结构

    数据集的概念 数据集通常是由数据构成的一个矩形数组,行表示观测,列表示变量.表2-1提供了一个假想的病例数据集. 不同的行业对于数据集的行和列叫法不同.统计学家称它们为观测(observation)和 ...

  5. 吴裕雄--天生自然C语言开发:指针

    #include <stdio.h> int main () { int var1; ]; printf("var1 变量的地址: %p\n", &var1 ) ...

  6. 吴裕雄--天生自然C语言开发:数组

    ] = {1000.0, 2.0, 3.4, 7.0, 50.0}; ]; #include <stdio.h> int main () { ]; /* n 是一个包含 10 个整数的数组 ...

  7. 吴裕雄--天生自然C语言开发:作用域规则

    #include <stdio.h> int main () { /* 局部变量声明 */ int a, b; int c; /* 实际初始化 */ a = ; b = ; c = a + ...

  8. 吴裕雄--天生自然C语言开发:存储类

    { int mount; auto int month; } { register int miles; } #include <stdio.h> /* 函数声明 */ void func ...

  9. 吴裕雄--天生自然C语言开发:数据类型

    #include <stdio.h> #include <limits.h> int main() { printf("int 存储大小 : %lu \n" ...

随机推荐

  1. CodeForces - 131C The World is a Theatre(组合数)

    题意:已知有n个男生,m个女生.现在要选t个人,要求有至少4个男生,至少1个女生,求有多少种选法. 分析: 1.展开,将分子中的m!与分母中n!相约,即可推出函数C. #pragma comment( ...

  2. 开源PLM软件Aras详解八 Aras之RelationshipTypes关系类详解

    在Aras中,在之前ItemType解析中有提到,Aras中实际ItemType对应的就是一张表,那么,ItemType与ItemType之间是如何关联的呢, 如果我们需要捋清楚ItemType与It ...

  3. nodejs(9)使用arttemplate渲染动态页面

    使用arttemplate渲染动态页面 安装 两个包 npm i art-template express-art-template -S 自定义一个模板引擎 app.engine('自定义模板引擎的 ...

  4. SPOJ 247 chocolate (CHOCLO)

    题目http://www.spoj.com/problems/CHOCOLA/ 把一整块巧克力分成一个一个单元,掰断每一横行有个代价值,掰断每个纵行也有个代价值,要你求最后的总代价值最小 这个题目放在 ...

  5. python-IDE使用

    集成开发工具 集成开发环境(IDE,Integrated Development Environment ) VIM 经典的linux下的文本编辑器,只有小白和的牛会用这个 Emacs linux文本 ...

  6. SQL基础教程(第2版)第2章 查询基础:2-2 算数运算符和比较运算符&2-3 逻辑运算符

    ● 包含NULL的运算,其结果也是NULL. ● 判断是否为NULL,需要使用IS NULL或者IS NOT NULL运算符. ■算术运算符 ■需要注意NULL ■比较运算符 这些比较运算符可以对字符 ...

  7. PAT Advanced 1094 The Largest Generation (25) [BFS,DFS,树的遍历]

    题目 A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level ...

  8. qt使用了qstackedwidget里面放置了widget后对该子widget设置的样式无效

    关键字:子窗口样式无效 QStackedwidget 问题: 我有一个对话框,里面放了一个qstackedwidget,qstackedwidget放了N个子窗口,使用addwidget添加上去了: ...

  9. POJ 1847:Tram

    Tram Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11771   Accepted: 4301 Description ...

  10. Java中常用的API(三)——缓冲区字符串

    前两节中分别介绍了Object和String,这一节主要介绍StringBuffer和StringBuilder. StringBuffer 由于String是不可变的,所以导致String对象泛滥, ...