can anybody telle me this

Discussion in 'C Programming' started by c beginner, Jun 17, 2007.

  1. c beginner

    c beginner Guest

    i have a confusion about pointer to functions.can anybody help me to
    overcome my confusion??
    c beginner, Jun 17, 2007
    #1
    1. Advertising

  2. c beginner

    Carramba Guest

    Carramba, Jun 17, 2007
    #2
    1. Advertising

  3. c beginner said:

    > i have a confusion about pointer to functions.can anybody help me to
    > overcome my confusion??


    What is it that is confusing you about pointers to functions?

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
    Richard Heathfield, Jun 17, 2007
    #3
  4. c beginner

    Sachin Guest

    On Jun 17, 9:13 pm, c beginner <> wrote:
    > i have a confusion about pointer to functions.can anybody help me to
    > overcome my confusion??


    function pointer holds address of function that you have specified.
    as you call function by pointer.

    fp = foo(int,int);
    so you can call as
    *fp(1,2);

    depending on requrement you just assign address of function to
    pointer.
    it will get executed through function pointer call.
    Sachin, Jun 18, 2007
    #4
  5. On Mon, 18 Jun 2007 08:39:50 -0000, Sachin <> wrote:

    >On Jun 17, 9:13 pm, c beginner <> wrote:
    >> i have a confusion about pointer to functions.can anybody help me to
    >> overcome my confusion??

    >
    >function pointer holds address of function that you have specified.
    >as you call function by pointer.
    >
    >fp = foo(int,int);
    >so you can call as
    >*fp(1,2);


    Don't anyone take any of this code as legitimate c.

    >
    >depending on requrement you just assign address of function to
    >pointer.
    >it will get executed through function pointer call.
    >



    Remove del for email
    Barry Schwarz, Jun 18, 2007
    #5
  6. c beginner

    Joe Wright Guest

    Sachin wrote:
    > On Jun 17, 9:13 pm, c beginner <> wrote:
    >> i have a confusion about pointer to functions.can anybody help me to
    >> overcome my confusion??

    >
    > function pointer holds address of function that you have specified.
    > as you call function by pointer.
    >
    > fp = foo(int,int);
    > so you can call as
    > *fp(1,2);
    >
    > depending on requrement you just assign address of function to
    > pointer.
    > it will get executed through function pointer call.
    >
    >

    Not quite like that. Let's define the function foo..

    int foo(int a, int b) {
    return a + b;
    }

    Now let's define a pointer to function returning int and taking two int
    arguments.

    int (*fp)(int, int);

    Now initialize fp..

    fp = foo;

    Now you call it through the pointer with..

    int x;
    x = fp(1, 2);

    --
    Joe Wright
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
    Joe Wright, Jun 18, 2007
    #6
    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. RikardN
    Replies:
    0
    Views:
    445
    RikardN
    May 28, 2004
  2. walala
    Replies:
    2
    Views:
    1,049
    walala
    Sep 13, 2003
  3. walala
    Replies:
    1
    Views:
    829
    Swapnajit Mittra
    Nov 19, 2003
  4. senthil
    Replies:
    0
    Views:
    606
    senthil
    Nov 21, 2003
  5. Catalin Porancea

    Can anybody help with this code?

    Catalin Porancea, Nov 6, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    1,336
    L. L.
    Nov 6, 2003
Loading...

Share This Page