function pointer and pointer to function

Discussion in 'C Programming' started by prashant.khade1623@gmail.com, Apr 10, 2008.

  1. Guest

    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,
    , Apr 10, 2008
    #1
    1. Advertising

  2. 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
    Philip Potter, Apr 10, 2008
    #2
    1. Advertising

  3. Guest

    On Apr 10, 4:17 pm, Philip Potter <> wrote:
    > 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
    , Apr 11, 2008
    #3
  4. wrote:
    > On Apr 10, 4:17 pm, Philip Potter <> wrote:
    >> 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.
    Philip Potter, Apr 11, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. glen stark
    Replies:
    2
    Views:
    702
    Ron Natalie
    Oct 10, 2003
  2. Fraser Ross
    Replies:
    4
    Views:
    1,041
    Fraser Ross
    Aug 14, 2004
  3. Replies:
    10
    Views:
    697
    Chris Torek
    Feb 4, 2005
  4. murgan
    Replies:
    6
    Views:
    4,861
    Thad Smith
    Dec 21, 2005
  5. Vijai Kalyan
    Replies:
    4
    Views:
    704
    Vijai Kalyan
    Nov 8, 2005
Loading...

Share This Page