C language learning notes (6): How to differentiate pointer arrays and array pointers from the surface of variable declarations, language learning pointers

Source: Internet
Author: User

C language learning notes (6): How to differentiate pointer arrays and array pointers from the surface of variable declarations, language learning pointers

Example:
Int * p [5] is a pointer Array
Int (* p) [5] is an array pointer
To distinguish the two, you only need to look at the modifier around variable name p.

 

Here we need to clarify two points:

1. No matter whether int * p [5] Or int (* p) [5], it should not be regarded as a whole, but as some modifiers to modify the Variable p, so that p can be accurately defined;
2. The priority of [] is higher than that of *, and the modifier of the same priority is used. The compilation method is from left to right.

 

* P [5] Because [] has a high priority, [] modifies the variable name p first, so p is an array name, and then looks at other modifiers, it can be found that it is an int * type array, that is, p is a pointer array.

(* P) [5] Since () and [] have the same priority, so compile from left to right, then * modify p first, so p is a pointer variable, then, let's look at other modifiers. We can see that p is an int array pointer.

 

 

There are still a lot of considerations for modifying variables during declaration, such:

Const int p and int const p are the same thing. They both represent an int type constant.

Const int * p can be seen from left to right as: int type constant pointer, const modifies int type, then * p indicates p is a pointer, so p is a pointer to a constant, and the value of p itself is variable.

Const int * const p Remove two const and you can see that it declares an int pointer, and then there are two modifiers, one used to limit the int (that is, the type pointed by the pointer ), A Variable p itself, so p is a pointer with immutable values, and the value to which it points must also be immutable.

Const int const * const p is still an int pointer, and the second const modifier * obviously has no meaning, so the above statements are actually completely consistent.

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.