Function Pointer as Argument in C
×

Function Pointer as Argument in C

81

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>
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:

output: 15



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments