function pointers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • askcq
    New Member
    • Mar 2007
    • 63

    function pointers

    [code=c]#include <stdio.h>

    static int my_function(int a)
    {
    printf("my_func tion: %d\n", a);
    return (2*a + 3);
    }

    int main(void)
    {
    int (*new_function) (int) = my_function;
    int x;

    x = (*new_function) (10);
    printf("main: %d\n", x);
    return 0;
    }
    [/code]

    i couldnt compile the above program
    wats the error
    Last edited by sicarie; Feb 20 '08, 07:38 PM. Reason: Code tagsa re [code=cpp] and after your code [/code]. Please use them. They want to be used. They like to be used.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by askcq
    i couldnt compile the above program
    wats the error
    Umm, wouldn't your complier tell you the error?

    Or is this a game and we're supposed to guess why?

    Comment

    • askcq
      New Member
      • Mar 2007
      • 63

      #3
      Originally posted by sicarie
      Umm, wouldn't your complier tell you the error?

      Or is this a game and we're supposed to guess why?
      no ..i couldnt get where is the error
      guide me

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by askcq
        no ..i couldnt get where is the error
        guide me
        You said it did not compile. How do you know that? Depending on the compiler, you will either get an error on the console, in a pop-up, or in a status window.

        Did you look for these? What compiler are you using?

        Comment

        • jaarmstr
          New Member
          • Jan 2008
          • 5

          #5
          There is nothing wrong with it!
          Sometimes a newline is required at the end of your program.
          All i can suggest is for you to put in a new line at the end of the file, that is press return to add an extra line. if this does not work i dont know because all i did is copy and paste then added the new line and it worked perfect.

          Comment

          • manjuks
            New Member
            • Dec 2007
            • 72

            #6
            Hi,

            Which compiler you are using? In gcc it works fine.

            Thanks,
            Manjunath

            Comment

            • askcq
              New Member
              • Mar 2007
              • 63

              #7
              iam using miracle C compiler ...it was availble from net...
              it says"parse error"

              Comment

              Working...