Advertisement
tresonance

functions_pointers

May 26th, 2020
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /*
  4. /*. FUNCTIONS POINTERS - PART 1
  5. /*  By MathsPhysic Code
  6. /*
  7.  
  8.  
  9. void display_differently(  void (*func_pointer)(int value1, int value2), int a, int b){  
  10.     //you can write like this
  11.     //(*func_pointer)(a, b);
  12.  
  13.     //or simply
  14.     func_pointer(a, b);
  15. }
  16.  
  17. //now let declare function to be pointed by function pointer
  18. void  display_green(int a, int b){
  19.     printf("I am the green function choose by function pointer\n");
  20.     printf("\x1B[32m a = %d, b = %d\n", a, b); // i just print in green color
  21. }
  22.  
  23. void display_yellow(int a, int b)
  24. {
  25.     printf("I am the yellow function choose by function pointer\n");
  26.     printf("\x1B[33m a = %d, b = %d\n", a, b); // i just print in yellow color
  27. }
  28.  
  29. int main(){
  30.     //display_differently( display_green  , 8, 5);
  31.                                                
  32.     //if i want to display yellow , simply change first parameter
  33.     display_differently(display_yellow, 8, 5);
  34.     return (0);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement