An example use of a function pointer source codeThis snippet submitted by Jayesh on 2006-07-13. It has been viewed 2654 times.Rating of 6.1 with 9 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 Add a snippet! |