【C++】关于指针函数

来源:互联网 发布:mac英雄联盟美服网站 编辑:程序博客网 时间:2024/05/20 13:36

指针函数的运用是面试中的经典题目。

#include <iostream>using namespace std;char test1(int t){return 'a' + t;}int main(){//形式1:返回类型(*函数名)(参数表) char (*funcPointer)(int);     funcPointer = test1;char temp = funcPointer(5); // (*funcPointer(5))...cout << temp << endl;//形式2:typedef 返回类型(*新类型)(参数表)typedef char(*typePointer)(int);typePointer tp;tp = test1;cout << (*tp)(6) << endl;//system("pause");}

还有一些比较容易混淆的概念,在这里给出代码表示。

函数指针 void (*f)()
函数返回指针 int* f()
const指针 const int *
指向const的指针 int *const
指向const的const指针 const int * const

0 0
原创粉丝点击