Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is the use of call back function in c?tell me with
example

Answer Posted / abdur rab

The caller and callee are decoupled.

The caller doesn't know who the callee is; all it knows is
that there is a callee with a certain prototype and
probably some restriction (for instance, the returned value
can be int, but certain values have certain meanings).

This would be useful during the creation of libraries where
in you do not want the logic to be embedded in the library.

hele let us consider a function do_action exists in the
library. It takes three parameters (int, int, and a
function)

The do_action does not know what the passed function does.
#include <stdio.h>

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

int sub ( int x, int y )
{
return ( x - y );
}

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

int div ( int x, int y )
{
return ( x / y );
}

int do_action ( int x, int y, int (*callback_function)
(int, int) )
{
return ( (*callback_function) ( x, y ) );
}

int main ( int argc, char* argv [] )
{
int x = 10;
int y = 2;

printf ("\nAdd %d", do_action ( x, y, &add ) );
printf ("\nSub %d", do_action ( x, y, &sub ) );
printf ("\nMul %d", do_action ( x, y, &mul ) );
printf ("\nDiv %d", do_action ( x, y, &div ) );

return ( 0 );
}

This is just an example. the usage of callback is more than
this

Is This Answer Correct ?    48 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is structure data type in c?

970


What is scope rule of function in c?

1029


How to establish connection with oracle database software from c language?

2141


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3636


Is c a great language, or what?

1049


Explain about C function prototype?

1026


largest Of three Number using without if condition?

1527


disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit

2017


Who invented b language?

1339


What is the difference between new and malloc functions?

1051


Why does notstrcat(string, "!");Work?

1084


What is the difference between int main and void main?

999


Why is python slower than c?

1023


Do you know the difference between malloc() and calloc() function?

1005


main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }

1449