On Wed, 27 Jun 2007 10:37:18 -0000, sid <ki***********@gmail.com>
wrote:
>Hi!
can anyone please tell me the use (application) of pointers to
functions?
e.g. void *func()
{
_ _ __
_____
}
Bad example. This is not a pointer to function. It is a function
returning pointer to void.
For a specific example, look in your reference at the qsort function
which takes a pointer to function as one of its parameters.
In short, you use a pointer to function whenever you want to refer to
a function indirectly.
One reason is because the determination of which function to
call is made at run time as in:
if (...) func_ptr = func1;
else if (...) func_ptr = func2;
...
func_ptr(...);
Another reason is because a pointer to function can appear in
certain places where a function cannot, such as in the argument and
parameter lists of a function (e.g., qsort again) or as a member of a
struct as in
struct x {
int x1;
float x2;
void (*func_ptr)(int,float);};
There are probably other reasons which I haven't thought of at
the moment.
As with all "when do I use a particular language feature" questions,
the answer is when that feature of the language helps you perform the
task you are designing the software for.
Language tutorials tell you how to use a language feature but your
question is one of design.
Remove del for email