其他分享
首页 > 其他分享> > 函数指针

函数指针

作者:互联网

基本概念

程序运行期间,每个函数都会占用一段连续的内存空间。而函数名就是该函数所占用内存区域的起始地址(也称入口地址)。我们可以将函数的入口地址赋值给一个指针变量,使该指针指向该函数。然后通过指针就可以调用这个函数。这种指向函数的指针变量称为“函数指针”。

定义形式

类型名(*指针变量名)(参数类型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
Arabic Hebrew Polish
Bulgarian Hindi Portuguese
Catalan Hmong Daw Romanian
Chinese Simplified Hungarian Russian
Chinese Traditional Indonesian Slovak
Czech Italian Slovenian
Danish Japanese Spanish
Dutch Klingon Swedish
English Korean Thai
Estonian Latvian Turkish
Finnish Lithuanian Ukrainian
French Malay Urdu
German Maltese Vietnamese
Greek Norwegian Welsh
Haitian Creole Persian  
  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