View Single Post
Join Date: Nov 2008
Posts: 18
Reputation: hellIon is an unknown quantity at this point 
Solved Threads: 0
hellIon hellIon is offline Offline
Newbie Poster

pointers to function

 
0
  #1
Nov 12th, 2008
hey guys
i am using miracle c compiler on windows xp....
i am trying to figure out how does pointer to functions work.....
i have gone thru many tutorials but all have them failed to compile....

  1.  
  2.  
  3. #include <stdio.h>
  4.  
  5. int sum(int x, int y)
  6. {
  7. return x + y;
  8. }
  9.  
  10. int product(int x, int y)
  11. {
  12. return x * y;
  13. }
  14.  
  15.  
  16. int main()
  17. {
  18. int a = 13;
  19. int b = 5;
  20. int result = 0;
  21. int (*pfun)(int, int);
  22.  
  23. pfun = sum;
  24. result = pfun(a, b);
  25. printf("\npfun = sum result = %d", result);
  26.  
  27. pfun = product;
  28. result = pfun(a, b);
  29. printf("\npfun = product result = %d", result);
  30.  
  31. }
  32. //this source code is from
  33. //http://www.java2s.com/Code/C/Function/Pointingtofunctions.htm
i get this error.......

C:\Program Files\Miracle C\work.c: line 21: Parse Error
'int (*pfun)(int, int)'
aborting compile

pls tell me wats wrong and also send me source code explaining the pointers to function
Reply With Quote