Programming

    Basics about programming

    Callback

    Callback((fonction de rappel en francais)) is a function passing by parameter of another function.

    See this example from wikipedia:

    #include `<stdio.h>`
    #include `<stdlib.h>`
    
    /* The calling function takes a single callback as a parameter. */
    void PrintTwoNumbers(int (*numberSource)(void)) {
        printf("%d and %d\n", numberSource(), numberSource());
    }
    
    /* A possible callback */
    int overNineThousand(void) {
        return (rand() % 1000) + 9001;
    }
    
    /* Another possible callback. */
    int meaningOfLife(void) {
        return 42;
    }
    
    /* Here we call PrintTwoNumbers() with three different callbacks. */
    int main(void) {
        PrintTwoNumbers(&rand);
        PrintTwoNumbers(&overNineThousand);
        PrintTwoNumbers(&meaningOfLife);
        return 0;
    }
    

    Loop

    Pass one time the loop:

    #include `<stdio.h>`
    
    int main(){
     int i=0;
     for(; i<4; i++)
     {
      if(i==2){
       continue; // NOTE this instruction
      }
    
      printf("%d, ", i);
     }
    
     return 0;
    }
    

    Output: 0, 1, 3,

    Pass all loop:

    #include `<stdio.h>`
    
    int main(){
     int i=0;
     for(; i<4; i++)
     {
      if(i==2){
       break; // NOTE this instruction
      }
    
      printf("%d, ", i);
     }
    
     return 0;
    }
    

    Output: 0, 1,