Skip to content

Instantly share code, notes, and snippets.

@arafatkamaal
Created October 18, 2013 08:45
Show Gist options
  • Save arafatkamaal/7038534 to your computer and use it in GitHub Desktop.
Save arafatkamaal/7038534 to your computer and use it in GitHub Desktop.
Function Pointers in C
#include <stdio.h>
int CallBackFunction(int i){
printf("This is the call back function %d\n", i);
}
int Operations(int (*func)(int)){
printf("\nRecieving function pointer\n");
(*func)(3);
printf("\nPassing function pointer\n");
AnotherOperation(*func);
AnotherOperation(func);
}
int AnotherOperation(int (*func)(int)){
printf("\nRecieved function pointer again");
(*func)(4);
}
int main(){
printf("\nPassing params\n");
int (*func)(int);
func = &CallBackFunction;
func(2);
Operations(func);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment