//
Main.c
Function_pointer
//
Created by Mac on 15/8/2.
Copyright (c) 2015 BJSXT. All rights reserved.
Requirements: The number of two integers by the function pointer to the 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.
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 (*p) (int,int); //define function pointers
p = add; //Pointer to the addition function
printf ("Add =%d\n", p (20,10));
p = Sub; //Pointer to subtraction function
printf ("Sub =%d\n", p (20,10));
p = mult; //Pointer to multiplication function
printf ("mult =%d\n", p (20,10));
p = divi; //Pointer to Division function
printf ("divi =%d\n", p (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