What is Function Pointer? Explain with example?
Answers were Sorted based on User's Feedback
Answer / inderchauhan
A pointer is a special kind of variable in C and C++ that
holds the address of another variable.
my first pointer
#include <iostream>
using namespace std;
int main ()
{
int firstvalue, secondvalue;
int * mypointer;
mypointer = &firstvalue;
*mypointer = 10;
mypointer = &secondvalue;
*mypointer = 20;
cout << "firstvalue is " << firstvalue << endl;
cout << "secondvalue is " << secondvalue << endl;
return 0;
}
firstvalue is 10
secondvalue is 20
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sanjay bhosale
function pointer is simply a pointer which holds the address of the function so we can call that function by using pointer.
It is helpful in situations where we are required to pass the function pointer as parameter to some previously defined functions.
for e.g.
in comparison method we may pass function pointer for function which will compare 2 items/objects and help to comparison method.
| Is This Answer Correct ? | 0 Yes | 0 No |
Are pointers integer?
Write a c program using for loop in switch case?
What is meant by recursion?
What is auto keyword in c?
What is c definition?
Explain how can I make sure that my program is the only one accessing a file?
what is the output of the code and how? main() { int *ptr,x; x=sizeof(ptr); printf("%d",x); }
write a program for egyptian fractions in c?
What is pointer and structure in c?
how to find out the reverse number of a digit if it is input through the keyboard?
What is a wrapper function in c?
What are multidimensional arrays?