An example use of a function pointer source codeThis snippet submitted by Jayesh on 2006-07-13. It has been viewed 12090 times.Rating of 5.6 with 104 votes #include<iostream> 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) { return(x*x); } /* function returning function pointer pt2Func */ pt2Func GetPtr(const char Code) { return (*sqr); } int main() { pt2Func xyz = GetPtr('j'); cout << (*xyz)(5) << endl; getch(); return 0; } More C and C++ source code snippets |