本系列为本人温习C++基础时所记的tips,欢迎各位同学指正,共同进步TvT。
An expression is composed of one or more operands combined by operators.
Until we know the types of operands, it’s not possible to know what a particular expression means.
取余
%
时,现版标准是余数与被除数正负号相同,商向0
取整When the precedent may be confusing, use parenthesis to assure correctness.
We use
;
here to separate operators with different precedents:- Relational and logical operators:
!; <, <=, >, >=(left associative); ==, !=; &&; ||
(from higher order to lower) - Bitwise operators:
~; <<, >>; &; ^; |
; How to deal with the sign bit of a signed integral value is machine-dependent, try to avoid it
- Relational and logical operators:
The shift operators(
<<, >>
) have lower precedence than the arithmetic operators but higher than the relational, assignment, or conditional operators… In a word, use()
to get rid of confusion.The result and type of an assignment is the same as the left-hand operand. Assignment is right associative.
int a; int* b; a=b