Priority rules for C-language declarations

Source: Internet
Author: User
Tags constant volatile

The priority rules for the C language declaration mentioned in Expert C programming ("C Expert programming") are as follows:

A declaration begins reading from its name and then reads sequentially in order of precedence;

B priority from high to low is:

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

B.2 suffix operator: bracket () means that this is a function, and square brackets [] indicate that this is an array;

B.3 prefix operator: asterisk * logo "points to ... The pointer ";

C if the const and/or volatile keyword is followed by a type specifier (such as a int,long, etc.), it acts on the type descriptor, and in other cases the const and/or volatile keywords are used for the pointer asterisk immediately to the left of it.

and give examples: char * const * (*next) ();

A next--next for the name of the declaration

B.1 (*next)--next as a pointing ... The pointer

B.2 (*next) ()--next is a function pointer

B.3 * (*next) ()--next is a function pointer that returns a point to ... The pointer

C char * const--A constant pointer to a character type

So char * const * (*next) means: Next is a function pointer that returns a constant pointer to the character type

Here we will analyze a statement ourselves:

Int (*foo ()) [];

Deduce it for yourself, and then look at the result: Foo is a function that returns a pointer to an integer array. Isn't that right? Here we look at the specific derivation process:

A foo--foo for the name of the declaration

B.2 foo ()--foo is a function

B.3 (*foo ())--foo is a function that returns a pointer to ... The pointer

B.2 (*foo ()) []--foo is a function that returns a pointer to an array

C Int (*foo ()) []--foo is a function that returns a pointer to an integer array

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.