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 a function pointer and how all to declare ,define
and implement it ???

Answer Posted / abdur rab

A pointer variable which holdes the address of a function
is a function pointer.

eg:
declaration of function pointer

void (*function_name)( int, int ) = NULL;

defining a function

void sum ( int x, int y )
{
printf ( "\nThe sum :%d", x + y );
}

void difference ( int x, int y )
{
printf ( "\nThe difference :%d", x - y );
}

using the function pointer in the place of function.
Remember to use the same prototype as declared.

int main ( int argc, char* argv [] )
{
function_name = sum; //short way of doing
function_name = &sum; // best practice

function_name ( 10, 20 ); //short way of doing
(*function_name) ( 10, 20 ); //best practice

function_name = &difference; //best practice
(*function_name) ( 10, 20 ); //best practice

return ( 0 );
}

output
======

The sum :30
The difference :-10

Is This Answer Correct ?    9 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain zero based addressing.

1014


What are the advantages of external class?

1054


Why is python slower than c?

1073


Write an efficient algo and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.

1057


What is c method?

986


How can I manipulate individual bits?

1032


What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25

1970


What is the difference between malloc() and calloc()?

1825


What are global variables and how do you declare them?

1079


Write a program to generate the Fibinocci Series

1224


What is the difference between a free-standing and a hosted environment?

1137


Is there a way to jump out of a function or functions?

1087


Explain how can I convert a string to a number?

1086


Explain which function in c can be used to append a string to another string?

1078


What is meant by type specifiers?

1123