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 = ∑ // 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

What is output redirection?

680


hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel

1406


What is table lookup in c?

620


What is cohesion in c?

533


What is equivalent to ++i+++j?

637






Why do we use static in c?

627


What do you understand by normalization of pointers?

617


How can a program be made to print the line number where an error occurs?

638


What is a string?

658


What are different storage class specifiers in c?

611


Which is the memory area not included in C program? give the reason

1495


What is register variable in c language?

594


i want to know the procedure of qualcomm for getting a job through offcampus

1923


What is c token?

599


What is a scope resolution operator in c?

739