Function Pointer

  • We can declare a pointer, that can point to each function.
  • Syntax :
returntype (*variable_name)(arguments ...);

void (*p)(int,char);

//here p ia an function pointer, which can point to a function that function should
//take two arguments as interger and character and it will return nothing (void).
  • How array name represents a base address in a same way function name represents a base address.


int call(int (*)(int,int) , int, int);
      int i=10,j=20,k;
      int (*p)(int,int);//function pointer declaration
      k = call(sum,i,j);//function call

      printf("k = %d\n",k);
int call (int (*p)(int,int),int m,int n)
      return ((*p)(m,n));

int sum(int m,int n)
     return m+n;
  • If a function is taking one argument as a function pointer that function called as a callback.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by

Up ↑

%d bloggers like this: