//
Main.c
Function_pointer
//
Created by Mac on 15/8/2.
Copyright (c) 2015 BJSXT. All rights reserved.
Requirements: The function pointer is a parameter to find two integers and, difference, product, quotient.
Knowledge Point: A function pointer is a pointer to a function that completes the operation by pointing to the function to be called. In fact, this pointer is the entry address that points to the function.
Remember: The function to be called must be the same as the declaration of the function pointer (includes: Return value type, number of arguments, and type)
#include <stdio.h>
int add (int, int);
int sub (int, int);
int mult (int, int);
int divi (int, int);
int main (int argc, const char * argv[])
{
int function (int (*p) (Int,int)); //Use function pointers as parameters
P is a pointer variable to a function that can point to a function whose type is integral and has two integer arguments. The type of P is represented by an int (*) (Int,int)
printf ("Add =%d\n", add (20,10));
printf ("Sub =%d\n", sub (20,10));
printf ("mult =%d\n", mult (20,10));
printf ("divi =%d\n", Divi (20,10));
return 0;
}
int add (int a,int b)
{
return a+b;
}
int sub (int a,int b)
{
return a-B;
}
int mult (int a,int b)
{
return a*b;
}
int divi (int a,int b)
{
return a/b;
}
C: two-digit subtraction with function pointers (function pointers as parameters)