C Expert Programming---priority rules

Source: Internet
Author: User

For some complex types of combinations, always do not understand, today read the "priority rules" this piece, with a further understanding, the rules are recorded here for their own learning query use.

Priority rules:

A, the declaration starts reading from its name, and then reads in order of precedence

B, priority from high to low in turn is

The part of the B.1 declaration that is enclosed in parentheses

B.2 suffix operator

Brackets () indicate that this is a function, and the square brackets "" means that this is an array

B.3 prefix operator: an asterisk * means "point to ... The pointer "

C, if the const and/or volatile keyword followed by a type specifier (such as int, long, and so on), then it acts on the type descriptor. In other cases, const or volatile acts on the

It's left next to the pointer asterisk.

Example:

char * const * (*next) ();

A, first, look at the variable name next, and notice that it is directly enclosed in parentheses

B.1 So first put the bracketed things as a whole, and concluded that "next is a point ... The pointer "

B, then consider what's outside the brackets and make a selection between the asterisk prefix and the parenthesis suffix

B.2 the higher priority is the right parenthesis, so "next is a function pointer pointing to a return ... The function "

B.3 then, the prefix "*" is processed to derive what the pointer refers to

C Finally, the "char *const" is interpreted as a constant pointer to a character

In summary, next is a pointer to a function that returns another pointer that points to a constant pointer of type char.

C Expert Programming---priority rules

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.