Join our subscribers list to get the latest news, updates and special offers directly in your inbox
Overview
1. Function Pointers in C
A function pointer in C is a pointer that stores the address of a function. This allows functions to be called indirectly, making them useful for callbacks, dynamic function calls, and implementing polymorphism in C.
2. Declaring and Using Function Pointers
return_type (*pointer_name)(parameter_list);
#include "stdio.h" // A normal function that takes two integers and returns an integer int add(int a, int b) { return a + b; } int main() { // Declare a function pointer int (*funcPtr)(int, int); // Assign function address to pointer funcPtr = add; // Call function using pointer int result = funcPtr(10, 20); printf("Sum: %d\n", result); // Output: Sum: 30 return 0; }
Explanation:
EmbeddedWala
EmbeddedWala Jun 14, 2023 0 29.1K
EmbeddedWala Apr 27, 2023 0 26.1K
EmbeddedWala Apr 26, 2023 0 22.5K
EmbeddedWala Feb 15, 2024 0 22.4K
EmbeddedWala Aug 30, 2022 0 20.2K
EmbeddedWala Jun 19, 2022 0 5.5K
This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies Find out more here