C pointer parsing ------ pointer expression

Source: Internet
Author: User

This article is my learning notes, welcome to reprint, but please note the Source: http://blog.csdn.net/jesson20121020

A pointer expression refers to an expression and the result is a pointer.

Example 1.

Int A, B;

Int array [20];

Int * P;

P = & A; // & A is a pointer expression, because the result of & A is a pointer.

Int ** q = & P; // & P is also a pointer expression.

* Q = & B; // * P and & B are both pointer expressions.

P = array;

P ++; // Similarly, this is a pointer expression.

Example 2.

Char * arr [10];

Char ** Parr = arr; // arr can be seen as a pointer representing the first address of the array. In this way, arr is also a pointer expression.

Char * s;

S = * Parr; // It is easy to see that * Parr is also a pointer expression.

S = * (Parr + 2); // Similarly, * (Parr + 2) is a pointer expression.


Because the result of a pointer expression is a pointer, the pointer expression also meets the four elements of the pointer, that is, the pointer type and the type pointed to by the pointer, the pointer value or the memory address pointed to by the pointer, and the memory occupied by the pointer.

In addition, it should be noted that when the result pointer of a pointer expression has clearly occupied the memory of the pointer itself, the pointer expression is a left value and can be auto-incremented, auto-subtraction. Otherwise, this pointer expression is not a left value. For example, & A in Example 1 is not a left value, because the result pointer without this expression, that is, the address of a does not occupy the memory, so it is not a left value, of course, you cannot perform auto-increment operations, but * Q is a left value, because the Q pointer has been allocated space during definition.





C pointer parsing ------ pointer expression

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.