吴裕雄--天生自然C语言开发:函数指针
#include <stdio.h> int max(int x, int y)
{
return x > y ? x : y;
} int main(void)
{
/* p 是函数指针 */
int (* p)(int, int) = & max; // &可以省略
int a, b, c, d; printf("请输入三个数字:");
scanf("%d %d %d", & a, & b, & c); /* 与直接调用函数等价,d = max(max(a, b), c) */
d = p(p(a, b), c); printf("最大的数字是: %d\n", d); return ;
}
#include <stdlib.h>
#include <stdio.h> // 回调函数
void populate_array(int *array, size_t arraySize, int (*getNextValue)(void))
{
for (size_t i=; i<arraySize; i++)
array[i] = getNextValue();
} // 获取随机值
int getNextRandomValue(void)
{
return rand();
} int main(void)
{
int myarray[];
populate_array(myarray, , getNextRandomValue);
for(int i = ; i < ; i++) {
printf("%d ", myarray[i]);
}
printf("\n");
return ;
}
吴裕雄--天生自然C语言开发:函数指针的更多相关文章
- 吴裕雄--天生自然C语言开发:指针
#include <stdio.h> int main () { int var1; ]; printf("var1 变量的地址: %p\n", &var1 ) ...
- 吴裕雄--天生自然C语言开发:函数
return_type function_name( parameter list ) { body of the function } /* 函数返回两个数中较大的那个数 */ int max(in ...
- 吴裕雄--天生自然 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语言开发:数组
] = {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" ...
随机推荐
- python学习---format、当前时间
1.数字格式化 format < :左对齐 > :右对齐 a = “随机数是{:>4d}”.format(1) 结果是0001 2.当前时间 import dat ...
- 每天一点点之laravel框架开发 - passport授权报invalid_credentials
{"error":"invalid_credentials","message":"The user credentials we ...
- Python中的常用内置对象之map对象
如果你了解云计算的最重要的计算框架Mapreduce,你就对Python提供的map和reduce对象有很好的理解,在大数据面前,单机计算愈加力不从心,分布式计算也就是后来的云计算的框架担当大任,它提 ...
- PHP+InfiniteScroll实现网页无限滚动加载数据实例
PHP+InfiniteScroll实现网页无限滚动加载数据实例,实现原理:当滚动条到底离网页底部一定长度的时候,向后台发送页数并获取数据. 首先我们在页面上先放置10条数据,即第一页,每一项都是p标 ...
- Vue-router(5)之 路由的before家族
beforeEach方法 import Vue from 'vue' import Router from 'vue-router' import Son1 from '@/view/New/son1 ...
- Swift 中调试状态下打印日志
首先我们应该知道Swift中真个程序的入口就是在AppDelegate.swift中.所以在打印日志在 AppDelegate.swift中是这样的 import UIKit @UIApplicati ...
- 02)MFC那几个基本文件介绍
1)首先是 类目录: 2)在这个工程里面,你找不到主函数,没有主函数,你能看到的 仅仅有这五个类 但是 你还看不到 这五个类对应的对象子啊哪里 而且 我们在写MFC程序的时候 我压 ...
- Kattis dragonball1 Dragon Ball I(最短路)
There is a legendary tale about Dragon Balls on Planet X: if one collects seven Dragon Balls, the Dr ...
- 有几个水洼(DFS)
#include <iostream> #include<cstdio> using namespace std; #define maxn 105 char field[ma ...
- 针对Oracle的一系列操作
一.有关于数据库导出dmp的语句. 1 将数据库TEST完全导出,用户名system 密码manager 导出到D:\daochu.dmp中exp system/manager@TEST file=d ...