function pointer and pointer to function

P

prashant.khade1623

Hi all,

Are function pointer and pointer to a function same ?

How do we declare a function pointer ?

How to declare an array of function pointers ?

Can you please give some examples for these.

Thanks,
 
P

Philip Potter

Hi all,

Are function pointer and pointer to a function same ?
Yes.

How do we declare a function pointer ?

It depends on the type of function you want to point to. For example, to
declare fp as a pointer to a function taking char * and returning int,
you'd say:

int (*fp)(char *);

All parenthesis () are necessary. If you say:

int *fp(char *);

then you're declaring fp as a function taking 'char *' and returning
'int *'.
How to declare an array of function pointers ?

When things get more complicated, such as arrays of function pointers,
or pointers to functions taking pointers to functions and returning a
pointer to function, you can still declare them directly, but you can
also do it in stages using typedefs. There's a wonderful example in the
FAQ, question 1.21.

Philip
 
P

prashant.khade1623

It depends on the type of function you want to point to. For example, to
declare fp as a pointer to a function taking char * and returning int,
you'd say:

int (*fp)(char *);

All parenthesis () are necessary. If you say:

int *fp(char *);

then you're declaring fp as a function taking 'char *' and returning
'int *'.


When things get more complicated, such as arrays of function pointers,
or pointers to functions taking pointers to functions and returning a
pointer to function, you can still declare them directly, but you can
also do it in stages using typedefs. There's a wonderful example in the
FAQ, question 1.21.

Philip

thanks for your help...

I need to know about declaring array of function pointers and how to
use them
 
P

Philip Potter

thanks for your help...

I need to know about declaring array of function pointers and how to
use them

I have already answered your question. I have quoted my answer above. If
you still don't understand, ask more specific questions - if you ask the
same question again, I can't tell which bit of my answer you haven't
understood.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top