Friday, August 24, 2007

Some more example of Function pointer.

Example1
Here i just want to write a program which deals with function pointer.
A function taking no argument returning a pointer to function which takes an arument of integer and that returns an integer.
/*
This methos return an int and takes an int
*/

int incr(int x)
{
x++;
cout<< "X val after incremented "<< x <<"\n";
return x;
}
/*
Here f is a function takes no argument ,returns a pointer to function(here say our incr() function) which takes an intger as argument that returns an integer..
Means f returns a function pointer that function pointer points to or hold the address of a function .Now tell me, what kind of fuction.... It can hold function of taking one int and return one int.
*/
int (*f())(int)
{
cout<< "Pls method returned \n";
return plus;
}
int main()
{
cout<<"Inside Main method Func ptr called "<< f()(5) << "\n";
}

cheer,
sahu

No comments: