top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C: Difference between normal function calling and using function pointer calling?

+1 vote
1,305 views

Can someone help me with the example when to use normal function calling and when pointer function calling. What was the reason for introducing pointer function calling in C?

posted Jul 7, 2014 by anonymous

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

2 Answers

+1 vote

One can use function pointers when he/she need to implement a Asynchronous mechanism for example you need a function whenever something happens. Or statically you don't know which function to call and based on the condition you may like to call a function.

Best examples are State Machine implementation where each function name is inserted into the state-machine and based on the event a function is called using the function pointer.

answer Jul 7, 2014 by Salil Agrawal
0 votes

w.r.t to system, nothing is different . I mean to say when you call a function as normal or using function then there is no difference in thread creation as compare to normal function call.

When two or more functions have same prototype then programmer uses function pointer.
Generally state machine uses table of function pointers as Salil mentioned.

answer Jul 7, 2014 by Rupam
Similar Questions
0 votes

Used the sizeof of function, which gives 1; why?
I want to know the size of the entire function. How to achive it?

#include <stdio.h>
void (*p)(int); 
void test_func(int data)
{
  printf("%d\n",data);
}

main(void)
{
    p = test_func;
    (*p)(4);
    printf("%d",sizeof(test_func));
}
+1 vote

int arr[ ] = { 1, 2 };
p = arr; /* p is pointing to arr */

How pointer p will behave ?

...