函数指针
作者:互联网
基本概念
程序运行期间,每个函数都会占用一段连续的内存空间。而函数名就是该函数所占用内存区域的起始地址(也称入口地址)。我们可以将函数的入口地址赋值给一个指针变量,使该指针指向该函数。然后通过指针就可以调用这个函数。这种指向函数的指针变量称为“函数指针”。
定义形式
类型名(*指针变量名)(参数类型1,参数类型2,...) int (*pf)(int,char); //例如
实例代码
#include<iostream> #include<cstdlib> using namespace std; void pint(int a,int b) { if(a<b) printf("hello"); } int main() { void (* pf)(int,int); pf = pint; pf(3,8); return 0; }
TRANSLATE with x English TRANSLATE with COPY THE URL BELOW Back EMBED THE SNIPPET BELOW IN YOUR SITE Enable collaborative features and customize widget: Bing Webmaster Portal Back
标签:函数,int,location,函数指针,document,指针 来源: https://www.cnblogs.com/LJianYu/p/15947140.html