function pointers in the C language

Source: Internet
Author: User
Tags mul

function pointers in the C language


Concept of function pointers: a function pointer is a pointer to a function code that is located in a code snippet.


Use of function pointers:


#include <stdio.h>

typedef struct (*fun_t) (int,int);

Fun_t PF;

int add (int a, int b)

{

return a+b;

}

int sub (int a,int b)

{

return a-B;

}

int mul (int a,int b)

{

return a*b;

}

int div (int a,int b)

{

return a/b;

}

int main ()

{

int RESULT1,RESULT2,RESULT3,RESULT4;

PF = add;

RESULT1 = PF (20,4);

printf ("Result1 is%d", result);

PF = Sub;

RESULT2=PF (20,4);

printf ("Result2 is%d", result2);

PF = Mul;

RESULT3 = PF (20,4);

printf ("Result3 is%d", RESULT3);

PF = div;

RESULT4=PF (20,4);

printf ("Result4 is%d", RESULT4);

return 0;

}

function pointers in the C language

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.