Hi folks
i faced this interview question in Bosch... they asked me to write prototype fora function that returns pointer to a function that returns integer
please let me know the prototype for above question..
Hi folks
i faced this interview question in Bosch... they asked me to write prototype fora function that returns pointer to a function that returns integer
please let me know the prototype for above question..
If this is an interview question, then you should probably at least put in some effort to solve it yourself. I'm not stopping anyone else from giving you the answer, but I'd suggest reading some tutorials and at least giving it a go (and posting the result if you have trouble).
There are a couple of decent function pointer tutorials online, and they aren't really that difficult if you are familiar with both functions and pointers.
The Function Pointer Tutorials - Index
Google "C Right-Left rule".
Last edited by Overworked_PhD; 04-29-2010 at 10:09 AM.
@DeadPlanet
Thanks for the link you provided.. i hope below prototype is correct ..
function returning pointer to a function with two int arguments that returns int
int (*pfunc(int ))(int, int)
Last edited by vijay s; 04-29-2010 at 01:27 PM.
Not quite, can you explain why you are doing:
(*pfunc(int)) /*what is the point of (int) here? */
Instead of hoping, check. It looks like you do not want pfunc to take any arguments, so you should actually write:Originally Posted by vijay s
Frankly, I would just reach for a typedef:Code:int (*pfunc(void))(int, int);
Code:typedef int (*Function)(int, int); Function pfunc(void);
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
That works as well, and probably preferred.
Typedef