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. Advertisements

  2. c beginner

    Carramba Guest

    Carramba, Jun 17, 2007
    1. Advertisements

  3. c beginner said:
    What is it that is confusing you about pointers to functions?
    Richard Heathfield, Jun 17, 2007
  4. c beginner

    Sachin Guest

    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

    depending on requrement you just assign address of function to
    it will get executed through function pointer call.
    Sachin, Jun 18, 2007
  5. Don't anyone take any of this code as legitimate c.

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

    Joe Wright Guest

    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

    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, Jun 18, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.