指针,C语言指针完全攻略:http://c.biancheng.net/c/pointer/
这个文章写的很不错,耐心看完。
指针函数重点:
附上一个demo:
#include <iostream> using namespace std; //============================================================================ //总结: // 1. int *pf (int,int); // 该语句声明了一个函数原型,该函数名为pf, // 该函数含两个int型参数,且该函数返回类型为整型指针类型,即int*。 // 2. int (*pf) (int,int); // 该语句定义了一个函数指针变量pf, // 该指针变量pf可以指向任意含有两个整型参数,且返回值为整型的函数 //============================================================================ int calc(int(*f)(int,int), int a, int b){ return f(a,b); } int add(int a, int b){ return a+b; } int min(int a, int b){ return a-b; } int main(){ cout << "指针函数" << endl; int a,b; cout << "输入a值:" << endl; cin>>a; cout << "输入b值:" << endl; cin>>b; cout << "输入y值代表加法,其它字符为减法:" << endl; char c; cin>>c; if(c == 'y' || c=='Y'){ cout << "加法计算结果为:" <<calc(add,a,b)<< endl; } else{ cout << "减法计算结果为:" <<calc(min,a,b)<< endl; } cout << "end." << endl; return 0; }