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

Why can’t we compare structures?

1275


How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?

1031


What is the difference between break and continue?

1527


What is static function in c?

1115


What is the newline escape sequence?

1078


How can I check whether a file exists? I want to warn the user if a requested input file is missing.

1150


Explain what does a function declared as pascal do differently?

1288


Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......

2189


What are the advantages of using macro in c language?

1129


Write the test cases for checking a variable having value in range -10.0 to +10.0?

2321


What is the translation phases used in c language?

1124


Explain what are run-time errors?

1090


What is a union?

1036


What are the advantages of the functions?

1162


Here is a neat trick for checking whether two strings are equal

1022