当前位置: 首页 > article >正文

1516-函数指针

笔记:

函数指向或引用内存中的数据。

可以用指针用来存储函数的地址=指向函数的指针。

说内存的时候,指的是程序运行的上下文。

随机存储器,RAM,称为主存。

应用程序的代码段,是用来存放可执行文件拷贝过来的机器码或者指令的。

指令先拷贝到主存,然后执行。

内存:存储指令,还有很多数据。

代码(我运行有点问题):

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h> // 包含字符串处理函数库
#include <math.h>
#include <time.h>

void PrintHello(char *name) {
	printf("Hello %s\n",name);
}

int Add(int a, int b) {
	return a+b;
}

int main()
{
	void (*ptr)(char*);
	ptr = PrintHello;
	ptr("Tom");
}

实际的函数指针用例:

只写了其中的一个

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h> // 包含字符串处理函数库
#include <math.h>
#include <time.h>

int compare(const void* a, const void* b)
{
	int A = *((int*)a);
	int B = *((int*)b);
	return abs(A) - abs(B);
}

int main()
{
	int i, A[] = { -31,22,-1,50,-6,4 };
	qsort(A, 6, sizeof(int), compare);
	for (i = 0; i < 6; i++) printf("%d", A[i]);
}

http://www.kler.cn/news/332873.html

相关文章:

  • 微信小程序操作蓝牙
  • Navicat Premium 12 for Mac中文永久版
  • 初识Django
  • 基于大数据技术的共享单车数据分析与辅助管理系统
  • 免费 Oracle 各版本 离线帮助使用和介绍
  • 基于GitLab 的持续集成环境
  • PHP__sleep和__wakeup有什么区别
  • 时间相关数据的统计分析(笔记更新中)
  • 我为什么决定关闭ChatGPT的记忆功能?
  • Java高效编程(16):在公共类中使用访问器方法,而不是公共字段
  • C++入门基础知识99——【关于C++ 成员运算符】
  • [C/C++开发]链接动态库在不同操作系统上的行为
  • 数据结构--二叉树的顺序实现(堆实现)
  • 移动技术开发:音乐播放器
  • 代码随想录 99. 岛屿数量
  • Studying-多线程学习Part2 - 互斥量死锁、lock_guard 与 unique_lock、call_once与其使用场景
  • Git介绍--github/gitee/gitlab使用
  • VMware tools菜单为灰色无法安装
  • 【MySQL 08】复合查询
  • 51单片机——矩阵键盘