C: two-digit subtraction with function pointers

Source: Internet
Author: User
Tags define function

//

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

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.