[A Day] pointer to the Function

Source: Internet
Author: User

Daily pointer to a function in CEvery day, I picked up a C-language shell, which grew up and formed thousands of miles.
Today's shells: What about pointer pointing to a function?In C language, a function itself is not a variable, but can define a pointer to a function. Such pointers are called function pointers, which can be assigned values and function parameters.1.Define function pointer: The definition of the function pointer must be consistent with that of the pointing function. This consistency is reflected in two aspects:1.1 consistent return values1.2 consistent ParametersFor example: function:IntFoo(IntA,IntB)The pointer to the function:Int(* P )(Int,Int)The function pointer returns the value. The parameter list must be the same as that of the function. (* p) brackets must exist.2. function pointer assignment:The value assignment statement: p = foo; can realize the function pointer pointing to the foo () function. The function is similar to the array:1. The value assignment does not require the Access & operator.2. Use indirect operators not required *.3. General Usage of function pointers:In the next section, we will explain a clever use of 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.