Pointer variable pointing to the function in C Language

Source: Internet
Author: User

Pointers in C language are an important data type in C language. They can not only point to int, char, char [], but also to functions.

# Include <stdio. h> // defines an addition int sum (int a, int B) {return a + B;} // defines a subtraction int minus (int a, int B) {return a-B;} // defines a method containing the pointer to a function. int count (int a, int B, int (* p) (int, int )) {return (* p) (a, B); // or return p (a, B) can also} int main () {// The function name is the address of the function, therefore, you can call printf ("% d \ n", count (10, 10, sum); printf ("% d \ n", count (10, 10, minus) as follows )); return 0 ;}

 

This article is from the "phper" blog, please be sure to keep this source http://janephp.blog.51cto.com/4439680/1290253

Related Article

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.