An example use of a function pointer source code

This snippet submitted by Jayesh on 2006-07-13. It has been viewed 9509 times.
Rating of 3.6 with 43 votes

using namespace std;
/* typedef a function pointer for a function returning int and taking argument as int.
typedef int(*pt2Func)(int);

/* function performing square */
int sqr(int x)
/* function returning function pointer pt2Func */
pt2Func GetPtr(const char Code)
 return (*sqr);

int main()
    pt2Func xyz = GetPtr('j');
    cout << (*xyz)(5) << endl;
    return 0;


More C and C++ source code snippets

Add a snippet!