
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Callbacks in C
The callback is basically any executable code that is passed as an argument to other code, that is expected to call back or execute the argument at a given time. We can define it in other words like this: If the reference of a function is passed to another function argument for calling, then it is called the callback function.
In C we have to use a function pointer to call the callback function. The following code is showing how the callback function is doing its task.
Example Code
#include<stdio.h> 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); }
Output
This is callback function. This is a normal function.
- Related Articles
- JavaScript Callbacks
- PHP Callbacks/Callables
- Use of Callbacks in Layered Architecture
- Promises Callbacks And Async/Await
- How can Forgotten timers or callbacks cause memory leaks in JavaScript?
- What are the arguments to Tkinter variable trace method callbacks?
- How to use API inside callbacks using jQuery DataTables plugin ?
- isless() in C/C++
- islessgreater() in C/C++
- isgreater() in C/C++
- modf() in C/C++
- isblank() in C/C++
- islessequal() in C/C++
- strxfrm() in C/C++
- Comments in C/C++

Advertisements