What is the precedence of arithmetic operators, assignment operators and relational operators?

烟雨青岚
Release: 2020-06-19 16:06:23
Original
51353 people have browsed it

What is the precedence of arithmetic operators, assignment operators and relational operators?

What is the precedence of arithmetic operators, assignment operators and relational operators?

The priority order is: arithmetic operators > relational operators > assignment operations.

Among arithmetic operators, the multiplication operator [*], division operator [/], and remainder operator [%] belong to the third level of priority, and the addition operator [ ] and subtraction operator The symbol [-] belongs to the fourth level.

The relational operator has 6 types of relations, namely less than, less than or equal to, greater than, equal to, greater than or equal to, and not equal to. Among them, the relational operator [< > <= >= ] belongs to the sixth level of priority, and the equal operator [==] and the not equal operator [!=] belong to the seventh level of priority.

The assignment operator [= = -= *= /= %= >>= <<= &= |= ^=] belongs to the fourteenth level of priority.

So, the priority order is: arithmetic operators are higher than relational operators and higher than assignment operations.

Extended information:

Priority related regulations:

1. Priority has nothing to do with the order of evaluation. For example, a b && b*c, although * has the highest priority, the evaluation order of this expression is from left to right. The priorities decrease from top to bottom, with the topmost operator having the highest priority and the comma operator having the lowest priority.

2. In the same priority, combine according to the associativity. The associativity of most operators is from left to right. Only three precedences are associative from right to left. They are unary operators, conditional operators, and assignment operators.

3. Pointers are optimal, and monocular operations are better than binocular operations. Such as plus and minus signs. Arithmetic operations are performed first, then shift operations, and finally bit operations. Please pay special attention to: 1 << 3 2 & 7 is equivalent to the final combination of (1 << (3 2))&7 logical operations.

Recommended tutorial: "C Language"

The above is the detailed content of What is the precedence of arithmetic operators, assignment operators and relational operators?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!