Advertisement
Archon

Function pointers

Dec 23rd, 2010
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement