Analysis of + + and--in C + +

Source: Internet
Author: User

1) C + + and--the function of the operator is increment and decrement, can be used as prefix or suffix expression;

int a = 1,B,C;B=A++;//1C=++A;//2

The difference between 1 and 2 is that the value of a in 1 is assigned to B, the value of a is increased by 1, so a b=1;2 starts with a 2,a increment of 1 and assigns a value to c,c=3; the last a=3.

y = (4 + x + +) + (6 + x + +);

2) The result of this expression is different from the result of running in different systems, because C + + chooses when to use the + + (-) operator for the variable as ";" to confirm. C + + does not guarantee that the value of x after (4 + x + +) immediately increases 1,c++ only to ensure that the value of x is increased two times at the end of the last type.

3) and pointer operator * Priority comparison: prefix increment and the * operator have the same precedence, followed by a right-to-left combination, the suffix increment precedence is higher than the prefix increment, but the suffix is incremented in a left-to-right way to combine.

Double x = *++pt;

The PT is a pointer, which means to add 1 to the next element and then add 1 to the value of the element that points to it.

4) for user-defined types, prefixes are more efficient to operate. The implementation of the suffix operation requires two steps (1) to copy the object, get the object copy (2) object plus 1, return the copied copy

This article is from the "leaf" blog, please be sure to keep this source http://fshine.blog.51cto.com/6122608/1582995

Analysis of + + and--in C + +

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.