Something that is easy to ignore in C language 2 [relationship between typedef and function]

Source: Internet
Author: User

Not to mention how common typedef is, the most common is typedef struct. So the powerful type definition character typedef can also be used to define functions. Do you know? The following accurate code can be used to explain the problem: typedef int (* MYFunc) (int x, int y); // MYFunc: int * Function (int x, int y) if the new name of the type pointer is too complex, we will temporarily throw the form parameter list, that is, the typedef int (* MYFunc), then MYFunc is actually the int type pointer connected to the parameter list, let's continue: int add (int x, int y); MYFunc pMYFunc; pMYFunc = add; pMYFunc (5, 6); // The result is hard to understand, right? It doesn't matter. You can use such an incomplete method to put it down a little: You need to understand pMYFunc = add; In this sentence, we should first: MYFunc = add; // right? Then: * MYFunc = * add; eventually: int = * add // is that a bit interesting? If we do this: pMYFunc = & add; // It works. In fact, this is the original sentence because p = fun; (implicit address) it works the same as p = & fun (explicit address fetch). You can verify it by programming.

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.