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

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

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

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

    return_type function_name( parameter list ) { body of the function } /* 函数返回两个数中较大的那个数 */ int max(in ...

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

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

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

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

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

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

  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. Linux学习-第二章(命令)20200216

  2. Java 跨系统开发隐患(一)

    换行符 主流系统换行符如下: Windows : \r\n Linux : \n Unix : \r 为了保证代码可以跨系统开发或使用,建议使用换行符时用下列语句获取: System.getPrope ...

  3. java8中的map 和reduce

    map 1.使用map让集合里面的数字翻倍. List<Integer> numbers = Lists.newArrayList(1,2,3,4,5);List<Integer&g ...

  4. winform操作windows系统计算器

    winform对系统计算器的调用,启动,最大化最小化显示,在mainwindow设置topmost=true时,正常显示计算器并置顶. /// <summary> /// 获取窗体的句柄函 ...

  5. Redis的数据结构和对象。

    一.简单动态字符串(simple dynamic string--SDS) Redis使用SDS表示字符串值,键值对都用SDS实现.SDS中的字符数组buf以空字符串结尾,好处是可以直接重用一部分C字 ...

  6. PAT 2011 秋

    A : World Cup Betting #include <cstdio> #include <iostream> #include <algorithm> u ...

  7. Coursera机器学习——Recommender System测验

    第一题本应该是基础题,考察Cost Function不同形式的表示方法,但却难住了我,说明基本概念掌握不够到位. 1. 在求和的部分,有两种可能,一种是(i,j)同时求和,即∑(i,j):r(i,j) ...

  8. 吴裕雄--天生自然 JAVA开发学习: 循环结构

    public class Test { public static void main(String args[]) { int x = 10; while( x < 20 ) { System ...

  9. PAT Basic 反转链表 (25) [链表]

    题目 给定⼀个常数K以及⼀个单链表L,请编写程序将L中每K个结点反转.例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4:如果K为4,则输出应该为4→3→2→1→5→6, ...

  10. UML-如何画SSD?

    1.SSD来自哪里?答:用例文本 2.如何为系统事件和操作命名? 3.SSD中的哪些需要放到词汇表中? SSD元素包含 1).操作名称 2).参数 3).返回数据 这些元素,必须要简洁.但别人可能不太 ...