C: two-digit subtraction with function pointers (function pointers as parameters)

Source: Internet
Author: User

//

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.