Detailed explanation of operator priority of C,

Source: Internet
Author: User

Detailed explanation of operator priority of C,
Operator priority of C #

Brackets. When learning mathematics, we know that we need to calculate the content in the brackets first. The same is true for C #. If multiple parentheses exist, they must be calculated from the inside out. Brackets have the highest priority.

Unary operator. Some operators have two operands, such as 2 + 3 and 6% 5, which are calledBinary Operators. Only one operand is calledUnary operatorThey have a higher priority than binary operators. Unary operators include:++ (Auto-increment), -- (auto-increment), and ),! (Non-logical).

* (Multiplication),/(Division), % (remainder).

+ (Plus),-(minus).

> (Greater than), <(less than), >=( greater than or equal to), <= (less than or equal).

= (Equal ),! = (Not equal).

7.& (Logical and).

Bytes| (Logical or).

BytesValue assignment operator. Including: =, + =,-=, * =,/=, and % =.

Note the following:Operators with the same priority are calculated from left to right (the assignment operator is opposite).

See the following code:

bool b = 20 - (15 - 8) * 2 > 10 && (2 % 2 * 2 + 2) > 2;Console.WriteLine(b);

Analysis: first, calculate the brackets with the highest priority. (15-8) get 7. (2% 2*2 + 2) Calculate % and * first, and then calculate +, if the result is 2, the expression is changed:

bool b=20-7*2>10&&2>2;

Next, the highest priority is 7*2, followed by subtraction, and changed:

bool b=6>10&&2>2;

Continue to calculate the two greater than signs, and get:

bool b=false&&false;

The final result is false:

Related Article

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.