Guest User

Untitled

a guest
Feb 18th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. void A(int a)
  4. {
  5. printf("I am in function A and here's a: %dn", a);
  6. }
  7.  
  8. // callback function
  9. void B(void (*ptr)(int b) )
  10. {
  11. // int b = 5;
  12. int b;
  13. printf("I am in function B and b = %dn", b);
  14. (*ptr) (b); // callback to A
  15. }
  16.  
  17. int main()
  18. {
  19. int c = 6;
  20. void (*ptr)(int c) = &A;
  21.  
  22. // calling function B and passing
  23. // address of the function A as argument
  24. B(ptr);
  25.  
  26. return 0;
  27. }
Add Comment
Please, Sign In to add comment