Function Pointer as Argument in C
0 325
function pointers as arguments in C is a technique that enables flexible and dynamic behavior in functions.
Function pointers allow you to pass the address of a function as an argument to another function.
This means you can design functions that can operate on different types of data or perform different operations based on the function pointer provided.
Syntax of Function pointer as argument in C
return_type function_name(data_type (*pointer_name)(arguments));Example:
// Program for Function Pointer in C #include<stdio.h>Output:void op(int (*func)(int, int), int a, int b); int add(int x, int y) { return x + y; } int main() { int a = 10, b = 5; op(add, a, b); return 0; } void op(int (*func)(int, int), int a, int b) { int output = func(a, b); printf("output: %d\n", output); }
output: 15
Share:
Comments
Waiting for your comments