About * P ++ (* P) ++ * (p ++)

Source: Internet
Author: User

Tag: * P ++ * (p ++) (* P) ++

    char ch[3]={‘a‘,‘c‘,‘e‘};    char *p=ch;

1,

         printf("%c\n",*p++);         printf("%c\n",*p);

Execution result 650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/A1/wKioL1RVt9yiIAlTAAAcwxIG2xM519.jpg "Title =" 11_2_1.jpg "alt =" wkiol1rvt9yiialtaaacwxig2xm519.jpg "/>

Note: first, * (pointer operator) and ++ (auto-incrementing operator) both belong to the single-object operator. The priority is the same and the combination is from right to left.

* P ++ executes * P first, that is, extracts the content of the Unit pointed to by P pointer, and then performs auto-increment operations on P, that is, the p Pointer Points to the next unit of the original unit, that is, the pointer P points to the C unit.

2,

    printf("%c\n",(*p)++);    printf("%c\n",*p);

Execution result:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/A1/wKioL1RVvP7BCE3wAAAfYkn_eKo571.jpg "Title =" 11_2_2.jpg "alt =" wkiol1rvvp7bce3waaafykn_eko571.jpg "/>

Note: (* P) ++ we all know that the content of P pointing to the unit is obtained by executing the brackets first. However, unlike * P ++, auto-increment is no longer P, it is the whole * P in the brackets. (at this time, the p pointer does not shift backward, but changes * P, that is, the auto-increment 1 is changed to B)

3,

    printf("%c\n",*(p++));    printf("%c\n",*p);

Execution result:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/4D/A2/wKiom1RVvJHC1cmKAAAV_LDrGvQ660.jpg "Title =" 11_2_3.jpg "alt =" wkiom1rvvjhc1cmkaaav_ldrgvq660.jpg "/>

Note: * (p ++) executes the P ++ in parentheses first, but if p ++ is still operated (this operation is to take the content that is *, the difference with the first one is that the first one is to get the content of P first, and the output operation is performed before the auto-increment of P, then perform auto-increment on P, so the output in the first sentence is still.

This article is from the "xingnallu" blog, please be sure to keep this source http://781588100.blog.51cto.com/9429625/1570899

About * P ++ (* P) ++ * (p ++)

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.