Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > function pointer and pointer to function

Reply
Thread Tools

function pointer and pointer to function

 
 
prashant.khade1623@gmail.com
Guest
Posts: n/a
 
      04-10-2008
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,
 
Reply With Quote
 
 
 
 
Philip Potter
Guest
Posts: n/a
 
      04-10-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
 
 
 
prashant.khade1623@gmail.com
Guest
Posts: n/a
 
      04-11-2008
On Apr 10, 4:17*pm, Philip Potter <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > 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


thanks for your help...

I need to know about declaring array of function pointers and how to
use them
 
Reply With Quote
 
Philip Potter
Guest
Posts: n/a
 
      04-11-2008
(E-Mail Removed) wrote:
> On Apr 10, 4:17 pm, Philip Potter <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>>> 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

>
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
diffrence between "function pointer" and "pointer to a function" murgan C Programming 6 12-21-2005 06:01 AM
Passing pointer to template function as argument to pointer to template function Vijai Kalyan C++ 4 11-08-2005 07:53 PM
Function pointer to void function and int function Giannis Papadopoulos C Programming 5 09-05-2005 09:06 PM
pointer to member function and pointer to constant member function Fraser Ross C++ 4 08-14-2004 06:00 PM
function pointer and member function pointer question glen stark C++ 2 10-10-2003 01:41 PM



Advertisments