RSS Forums RSS

pointers to function

Please support our C advertiser: Programming Forums
Reply
Posts: 18
Reputation: hellIon is an unknown quantity at this point 
Solved Threads: 0
hellIon hellIon is offline Offline
Newbie Poster

pointers to function

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


#include <stdio.h>

int sum(int x, int y)
{
   return x + y;
}

int product(int x, int y)
{
   return x * y;
}


int main()
{
   int a = 13;
   int b = 5;
   int result = 0;
   int (*pfun)(int, int);

   pfun = sum;
   result = pfun(a, b);
   printf("\npfun = sum   result = %d", result);

   pfun = product;
   result = pfun(a, b);
   printf("\npfun = product         result = %d", result);

}
//this source code is from
//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
AddThis Social Bookmark Button
Reply With Quote  
Posts: 273
Reputation: Sci@phy will become famous soon enough Sci@phy will become famous soon enough 
Solved Threads: 42
Sci@phy's Avatar
Sci@phy Sci@phy is offline Offline
Posting Whiz in Training

Re: pointers to function

  #2  
Nov 12th, 2008
It works on my Dev-cpp (mingw, gcc) compiler, and I can't see any problem with code, so it's probably something about your compiler.
Reply With Quote  
Posts: 18
Reputation: hellIon is an unknown quantity at this point 
Solved Threads: 0
hellIon hellIon is offline Offline
Newbie Poster

Re: pointers to function

  #3  
Nov 12th, 2008
Originally Posted by Sci@phy View Post
It works on my Dev-cpp (mingw, gcc) compiler, and I can't see any problem with code, so it's probably something about your compiler.


so wat compiler do u suggest......
Reply With Quote  
Posts: 7,460
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 676
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: pointers to function

  #4  
Nov 12th, 2008
>i am using miracle c compiler
Miracle C is a horrible compiler. Trash it and get anything else, or you'll have to suffer through constant battles of perfectly valid code failing to compile or not working correctly.

Try Code::Blocks, Turbo C++, or Visual C++.
Last edited by Narue : Nov 12th, 2008 at 9:07 am.
I'm here to prove you wrong.
Reply With Quote  
Posts: 18
Reputation: hellIon is an unknown quantity at this point 
Solved Threads: 0
hellIon hellIon is offline Offline
Newbie Poster

Re: pointers to function

  #5  
Nov 12th, 2008
Originally Posted by Narue View Post
>i am using miracle c compiler
Miracle C is a horrible compiler. Trash it and get anything else, or you'll have to suffer through constant battles of perfectly valid code failing to compile or not working correctly.

Try Code::Blocks, Turbo C++, or Visual C++.

i am learning c
so how can i use visual c++,turbo c++......
pls can u suggest a compiler for windows.........
its urgent.....
Reply With Quote  
Posts: 7,460
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 676
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: pointers to function

  #6  
Nov 12th, 2008
>i am learning c
C++ compilers can compile C. Usually all you have to do is name the source file *.c instead of *.cpp.

>pls can u suggest a compiler for windows.........
I suggested three of them. They're all easy to install and use. Stop being lazy.

>its urgent.....
Not for me.
I'm here to prove you wrong.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 465 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:18 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC