top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are usage of function pointer in C/C++?

+4 votes
740 views

Can someone explain me the usage of function pointer? Probably with real time examples ?

posted Oct 18, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+3 votes

Three usage -
1. Callback functionality
2. State-machine Implementation (basically where u need a array of functions and need to call one of them on need basis)
3. To bind function at run time as per requirment.

In the large scale development . each team develops some part of software .
and provide function pointer so other team can bind their function with these pointer.

Like if one vender don not want to give the code then he will give binary , header file and User manual
In user manual he will describe the the function argument their purpose. So that user can bind their function with pointer and can use the code of vender.

answer Oct 19, 2013 by Vikas Upadhyay
thanks vikas, and can you provide some info about callback ?
+2 votes

Two usage -
1. Callback functionality
2. State-machine Implementation (basically where u need a array of functions and need to call one of them on need basis)

answer Oct 18, 2013 by Jai Prakash
Similar Questions
+7 votes
#include<stdio.h>

int &fun()
{
   static int x;
   return x;
}   

int main()
{
   fun() = 10;
   printf(" %d ", fun());

   return 0;
}

It is fine with c++ compiler while giving error with c compiler.

+1 vote

I have written a simple program and stored it with .c file,
When i compiled it with g++ it is getting compiled and giving the proper output when i run that,
but when i compile the same using gcc then it is throwing error.

Below is the sample .c file
#include<stdio.h>
struct A{
        private:
        int a;
        public:
        int sum(){
        a=10;
        }
        void print()
        {
        printf("%d\n",a);
        }
        A()
        {
                printf("Constructor\n");
        }
        A(int b)
        {
                printf("Copy Constructor\n");
        }
        ~A()
        {
                printf("Destructor\n");
        }
};
main()
{
        struct A a(10);
        a.sum();
        a.print();
}
+7 votes

What will the function rewind() do? How can we use it?

...