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..
Printable View
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".
@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)
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:Quote:
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);
That works as well, and probably preferred.
http://cboard.cprogramming.com/c-pro...1-typedef.html