daily pastebin goal
62%
SHARE
TWEET

Function pointers

Archon Dec 23rd, 2010 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. typedef void func_t(int);
  4.  
  5. //these two function declarations are equivalent:
  6. void print1(int x);
  7. func_t print2;
  8.  
  9. func_t *p; //p is a pointer to a function;
  10. void (*q)(int); //equivalent function-pointer declaration
  11.  
  12. void print(int x){
  13.    printf("%d\n", x);
  14. }
  15.  
  16. int main(){
  17.    p = &print; //p now points to the "print" function
  18.    
  19.    //equivalent function calls:
  20.        p(5);
  21.     (*p)(5);
  22.    print(5);
  23. }
RAW Paste Data
Top