callback function in C

WBOY
Release: 2023-09-01 23:25:10
forward
852 people have browsed it

callback function in C

A callback function is basically any executable code passed as a parameter to other code that is expected to be called or executed at a specific time. We can define it in other words as follows: If a reference to a function is passed as a parameter to another function to call, it is called a callback function.

In C language, we must use function pointers to call callback functions. The following code shows how the callback function performs its task.

Sample code

#include void my_function() { printf("This is a normal function."); } void my_callback_function(void (*ptr)()) { printf("This is callback function.

"); (*ptr)(); //calling the callback function } main() { void (*ptr)() = &my_function; my_callback_function(ptr); }

Copy after login

Output

This is callback function. This is a normal function.
Copy after login

The above is the detailed content of callback function in C. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!