The function itself cannot be passed as an argument to another function.However, by utilising a function pointer, we can pass the reference to a function as a parameter.As the function parameter is supplied as a pointer that contains the address of arguments, this technique is known as a call by reference. .
#include<stdio.h>
//function to display even numbers
int help(void (*show)())
{
for(int i=0;i<=10;i+=2)
{
show(i);
}
return 0;
}
//printing the value
void print(int val)
{
printf("%d ",val);
}
int main()
{
void (*show)(int);
printf("The even values are :");
help(print);
return 0;
}
Output :
The even values are :0 2 4 6 8 10
What Happened Above ?In the above Program, we write two function to help to find even number and print to print the numbers and use function arguments in the main function.
Login/Signup to comment