//pointer to function imp one please go to bellow link
//https://[Log in to view URL]

In C, a function pointer is a pointer that points to the address of a function
in memory. It can be used to call a function indirectly, through the function
pointer.

To declare a function pointer, you need to use the typedef keyword and specify
the return type and the parameters of the function. Here is an example:


typedef int (*func_ptr)(int, int);
This declares a function pointer func_ptr that points to a function that takes
two int arguments and returns an int.

To assign the address of a function to a function pointer, you can use the
address-of operator (&). For example:


int add(int a, int b) {
    return a + b;
}

func_ptr fp = &add;
To call a function through a function pointer, you can use the dereference
operator (*). For example:


int result = (*fp)(10, 20);
This will call the add function and pass it the arguments 10 and 20, and the
result will be stored in the result variable.

Function pointers can be useful in a variety of contexts, such as implementing 
callback functions or abstracting function calls.

---------------------------------------------------------------------------------

typedef ex in c

#include <stdio.h>

typedef int Age;

int main() {
  Age myAge = 30;
  printf("My age is %d\n", myAge);
  return 0;
}

---------------------------------------------------------------------------------

example program in c
Here is an example C program that demonstrates the use of function pointers:


#include <stdio.h>

// Declare a function pointer type that takes two integers and returns an integer
typedef int (*func_ptr)(int, int);

// Declare some functions that can be called through the function pointer
int add(int a, int b) {
    return a + b;
}

int subtract(int a, int b) {
    return a - b;
}

int multiply(int a, int b) {
    return a * b;
}

int main() {
    // Declare a function pointer and initialize it to the address of the add
    //function
    func_ptr fp = &add;

    // Call the add function through the function pointer
    int result = (*fp)(10, 20);
    printf("Result: %d\n", result);

    // Assign the function pointer to the address of the subtract function
    fp = &subtract;

    // Call the subtract function through the function pointer
    result = (*fp)(10, 20);
    printf("Result: %d\n", result);

    // Assign the function pointer to the address of the multiply function
    fp = &multiply;

    // Call the multiply function through the function pointer
    result = (*fp)(10, 20);
    printf("Result: %d\n", result);

    return 0;
}
This program declares a function pointer fp of type func_ptr, which is a function
that takes two int arguments and returns an int. It then assigns the address of
the add function to the function pointer, calls the add function through the
function pointer, and prints the result. It then assigns the address of the
subtract function to the function pointer, calls the subtract function through
the function pointer, and prints the result. Finally, it assigns the address of
the multiply function to the function pointer, calls the multiply function
through the function pointer, and prints the result.

When compiled and run, this program will print the following output:

Copy code
Result: 30
Result: -10
Result: 200
 ----------------------------------------------------------=-------------------

#include <stdio.h>

int add(int a,int b){
    int sum=a+b;
    return sum;
}

int main() {
    int a,b,s;
    int (*fp)(int,int);
    fp=add;
    scanf("%d %d",&a,&b);
    s=(*fp)(a,b);
    printf("%d",s);
}

#include<stdio.h>

// function declaration
int areaRectangle(int, int);

int main() {
    int length, breadth, area;
    
    // function pointer declaration
    // note that our pointer declaration has identical 
    // arguments as the function it will point to
    int (*fp)(int, int); 
    
    printf("Enter length and breadth of a rectangle\n");
    scanf("%d%d", &length, &breadth);
    
    // pointing the pointer to functions memory address
    fp = areaRectangle;
    
    // calling the function using function pointer
    area = (*fp)(length, breadth); 
    
    printf("Area of rectangle = %d", area);
    return 0;
}

// function definition 
int areaRectangle(int l, int b) {
    int area_of_rectangle = l * b;
    return area_of_rectangle;
}

#if 0
int add(int a,int b){
    int sum;
    sum=a+b;
    return sum;
}

int main(){
    int n1,n2,s;
    
    scanf("%d %d",&n1, &n2);
    
    // ptr is a pointer to function fun():- add()
    int (*ptr)(int,int)=&add;
    
    //s=add(n1,n2);
    s=(*ptr)(5,6);
                   //ptr=&add;
    printf("%d",s);
}

#if 0
void fun(int a){
    printf("the value of n1 : %d",a);
}

int main(){
    int n1;
    
    scanf("%d",&n1);
    void (*ptr)(int)=&fun;
    (*ptr)(n1);
}

#include<stdio.h>

float add(int, int);
float multiply(int,int);
float divide(int,int);
float subtract(int,int);

int main() {
    int a, b;
    float (*operation[4])(int, int);

    operation[0] = add;
    operation[1] = subtract;
    operation[2] = multiply;
    operation[3] = divide;
    
    printf("Enter two values ");
    scanf("%d%d", &a, &b);
    
    float result = (*operation[0])(a, b);
    printf("Addition (a+b) = %.1f\n", result);
    
    result = (*operation[1])(a, b);
    printf("Subtraction (a-b) = %.1f\n", result);
    
    result = (*operation[2])(a, b);
    printf("Multiplication (a*b) = %.1f\n", result);
    
    result = (*operation[3])(a, b);
    printf("Division (a/b) = %.1f\n", result);
    
    return 0;
}

float add(int a, int b) {
    return a + b;
}

float subtract(int a, int b) {
    return a - b;
}

float multiply(int a, int b) {
    return a * b;
}

float divide(int a, int b) {
    return a / (b * 1.0);
}

#endif

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: