C/C++ callback function example

C/C++ callback function example

C/C++ callback function example


資料來源: Gemini


code

#include <stdio.h>

void do_something(int value) {
  printf("Doing something with value: %d\n", value);
}

void call_with_callback(int arg, void (*callback)(int)) {
  int result = arg * 2;
  callback(result); // Call the callback function with the processed value
}

int main() {
  call_with_callback(5, do_something); // Pass do_something as callback
  return 0;
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *