Semantic Analysis of C/C ++ complex symbol combinations

Source: Internet
Author: User
ArticleDirectory
    • Semantic Analysis of C/C ++ complex symbol combinations
Semantic Analysis of C/C ++ complex symbol combinations: Left-right method

Start from the variable, start from the lower right corner, and rotate it counter-clockwise. When () is used as parentheses, there is no need to interpret the delimiters. If it is used as a function, it is interpreted as "a function of the ×× type is returned ".

Instance 1
 
INT (* pa [10]) (INT, INT );

Analysis result: [] is displayed at the beginning of PA, indicating that PA is an array, which is rotated counterclockwise and X is displayed, indicating that the elements in the array are pointers and parentheses are displayed, continue to rotate, see the function, so this pointer points to the function. The meaning of this pa is an array of 10 function pointers. Use typedef to define this instance. Typedef int (* mytype) (INT, INT); mytype pa [10];

Instance 2
 
Int * Fun (INT, INT) [10];

Analysis results: Fun, first saw the function, indicating that fun is a function, then saw a pointer, indicating that the function of fun returns a pointer, and then saw an array, the returned pointer is a pointer to a 10-element array. Fun is a function that returns 10 element array pointers. Use typedef to define typedef int * mytype [10]; mytype fun (INT, INT );

Note:

In fact, these complex symbols should not appear frequently during programming.ProgramReadability will become difficult to understand. Basically, typedef is used to define instructions to increase readability. For example, the above two instances can be defined using typedef in the following mode. Program readability is greatly enhanced.

 
// Typedef of instance 1 implements typedef int (* mytype) (INT, INT); // typedef a function pointer mytype pa [10]; // defines the array of function pointers. // Typedef of instance 2 implements typedef int * mytype [10]; // defines the array pointer mytype fun (INT, INT); // defines the function that returns the array pointer.
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.