C + +: The difference between (*p) + + and * (p++) and *p++

Source: Internet
Author: User

Tag: size operation has no increment operator precedence nbsp ext font New

1. Understanding the self-increment decrement operator
(1) post-increment-decrement operator precedence > pre-increment decrement operator.
(2) The pre-increment-decrement operator "variable is first self-decrement and then used".
(3) The post-increment-decrement operator "variable is first used for re-increment self-decrement".
2. The * operator and the pre-increment-decrement operator are all 3-level operators, but the predecessor-increment-decrement operator takes precedence over the * operator.
The post-increment-decrement operator is a level 2 operator. The smaller the progression, the higher the priority.

3. Following this rule, you can understand: if int a=100,*p=&a;
(1) *p++: The post-increment operator takes precedence, first using p, that is, pointing to a first, and then p pointing to the next inner deposit cell. No difference from * (p++).
Parentheses indicate that the operator takes precedence, and then the increment operator takes precedence over *, so the parentheses are superfluous.
(2) (*p) + + indicates that P points to an element plus 1.
(3) * (++P) Here P first add 1, then take the element that P points at this time.

C + +: The difference between (*p) + + and * (p++) and *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.