Pointer to Functions

This is a discussion on Pointer to Functions within the C Programming forums, part of the General Programming Boards category; Hi everyone; [SOLVED] I make a try to use a pointer to function. However I get a garbage value. Could ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    93

    Pointer to Functions

    Hi everyone;
    [SOLVED]

    I make a try to use a pointer to function. However I get a garbage value. Could you please check my code?

    Code:
    #include <stdio.h>
    int main(void){
    int (*p)(int,int);
    int f1(int x, int y);
    p=f1;
    int a=5;
    int b=3;
    int c=(*p)(a,b);
    printf("%d",*p);
    return 0;
    }
    int f1(int x, int y){
    return ((x+y)*(x+y));
    }
    Edit: I see when I use printf("%d",c); instead of printf("%d",*p); I get the correct result. I wish I was able to delete the post.
    Last edited by GokhanK; 08-15-2013 at 12:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 02-02-2013, 09:33 PM
  2. Need help with beginner pointer functions.
    By Mo777 in forum C Programming
    Replies: 9
    Last Post: 02-17-2011, 03:30 PM
  3. Pointer-to-member functions
    By EvilGuru in forum C++ Programming
    Replies: 21
    Last Post: 01-12-2008, 04:50 AM
  4. Pointer to functions
    By seizmic in forum C Programming
    Replies: 13
    Last Post: 09-08-2005, 01:56 PM
  5. pointer functions
    By kurz7 in forum C Programming
    Replies: 2
    Last Post: 06-04-2003, 08:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21