Example of Callbacks in c

Asked

Viewed 569 times

0

I would like an example of using callback in c that allows logging callbacks to be called when an event occurs.

1 answer

1

In C the "callback" are not equal to the javascript that are much more imploded, are simply functions that are passed in arguments of other functions using function pointers.
Take this example:

#include<stdio.h> 

void funcaoA() 
{ 
    printf("Olá"); 
} 

void funcaoB(void (*func)()) 
{ 
    (*func) ();
    printf(" Mundo \n");
} 

int main() 
{ 
    void (*func)() = &funcaoA; 

    funcaoB(*func); 

   return 0; 
} 

You can test the code above here.
You find cool material to read on the subject here and here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.