C/C ++ function pointer variables and function pointer Parameters

Source: Internet
Author: User

Guide

// Function pointer: pointer to a function
// Pointer function: the function that returns a pointer.

// Form 1: return type (* function pointer name) (Form parameter table) (C/C ++)
// Form 2: typedef return type (* New function pointer type) (Form parameter table) (C/C ++)
// Form 3: typedef return type (Class Name: * New function pointer type) (Form parameter table) (C ++)



For example:
INT (* p) (); // * P indicates the function pointer variable, which is followed by () indicates that the pointer variable points to a function.
Typedef int (* FP) (); // * the FP after it indicates the new function pointer type defined by typedef, which is followed by a () indicating that the type points to a function

Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------

The following are examples,
/* Author: Eric */
# Include <stdio. h>
Typedef int (* FP) (INT, INT );
Int fuc1 (int I, Int J)
{
Return (I + J );
}

Int fuc2 (int I, Int J, FP P)
{
Return P (I, j );
}

Void main ()
{
Fp p = fuc1;
Printf ("% d", fuc2 (100,200, p ));
}

Tested on VC, Dev C ++, And Turbo C

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.