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
What is output redirection?
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
What is table lookup in c?
What is cohesion in c?
What is equivalent to ++i+++j?
Why do we use static in c?
What do you understand by normalization of pointers?
How can a program be made to print the line number where an error occurs?
What is a string?
What are different storage class specifiers in c?
Which is the memory area not included in C program? give the reason
What is register variable in c language?
i want to know the procedure of qualcomm for getting a job through offcampus
What is c token?
What is a scope resolution operator in c?