Operators (Value assignment, auto-increment and auto-subtraction), expressions, statements, and priority tables

Source: Internet
Author: User

The item on the left of the value assignment operator must be the name of a variable. Example: 2002 = BMW; error 1. the multiplication and division operator is higher than the addition and subtraction operator, and the operator priority is the same from left to right. 2. The priority of the value assignment operator is only higher than that of the comma operator. The combination direction is from right to left. Note: The assignment operator, condition operator, and single object operator are operated from right to left, and other operators are operated from left to right.

++

1. int A = 1; int B = 2; B + A ++ = 3, that is, the first operation is followed by a = 2, B = 2; B + (++) = 4; that is, first add and then calculate a = 2, B = 2B ++ A = 3; that is, (B ++) + A = 3, A = 1, B = 3; int A = 1;
Int B = 2;
Int c = (a ++) + (A ++); // warning reason: multiple new modifications
Printf ("% d, % d, % d \ n", A, B, C );
-Expression similar to ++: The expression has a return value. For example, 6 + (C = 3 + 8) is valid because there are two word expressions, each of which has a value and the result is 17, but it is not recommended to use the statement: minimum unit of program execution, ending with a semicolon (semicolon. Example: Legs = 4 expression legs = 4; statement priority
Priority Description Operator
1 Brackets (), []
2 Plus or minus sign + ,-
3 Auto-increment and auto-increment, not ++ ,--,!
4 Multiplication, division, and remainder *,/, %
5 Addition and subtraction + ,-
6 Shift operation <,>,>
7 Size relationship ]>,> =, <, <=
8 Equality = ,! =
9 Bitwise AND &
10 Bitwise OR ^
11 By bit or |
12 Logic and &&
13 Logic or |
14 Conditional operation ? :
15 Value assignment =, + =,-=, * =,/=, % =
16 Bit value assignment & =, | =, <=, >>=, >>>> =

 

Operators (Value assignment, auto-increment and auto-subtraction), expressions, statements, and priority tables

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.