Thread: Need Help on function pointers

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    Bangalore, INDIA
    Posts
    43

    Need Help on function pointers

    consider the below prototype is a function prototype which does bubble sorting
    Code:
    void bubble(int *a, int elements, int (*fptr) (const int *m, const int *n))
    now consider there is a function which does the compating part
    Code:
    int comp(const int *m, const int *n)
    so now i can use the function comp in the function bubble to sort the values.....but how to pass the parameters to the function comp..

    for example the calling function is as below
    Code:
    int a[]={2,7,3,9,1,0};
    bubble(a,6,comp) ;
    Here i could not understand how to pass the parameters to the function comp....?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by enggabhinandan
    Here i could not understand how to pass the parameters to the function comp....?
    It seems as though you've done it correctly (you tell bubble the starting location, the array size, and the comparison function to use) -- could you clarify your question?

    [edit]Show the definition of bubble: there is likely some place for a comparison, wherewhich you ought to be doing something akin to:
    Code:
    if ( comp( &a[i], &a[j] ) { /*... */ }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    Bangalore, INDIA
    Posts
    43
    Hey, Thanks.....i went through the code and i found there ......i got it....thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  2. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM
  3. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. function pointers and member functions
    By thor in forum C++ Programming
    Replies: 5
    Last Post: 03-19-2002, 04:22 PM