Article directory
arithmetic
+
-
*
/ 除法,整数则整除。
% 取余
bit
& 与
| 或
~ 非
^ 异或
<< 左移
>> 右移
assign
=
+=
-=
*=
/=
&=
^=
|=
<<=
>>=
logic
0: false
non-0: true
! 非
&& 与
|| 或
Compare
Returns 1 if true, 0 if false.
== 等于
!= 不等
< 小于
<= 小于等于
> 大于
>= 大于等于
self-increment
Expression: A formula that represents a value.
1+2 is an expression with the value 3.
a+1 is an expression with the value a+1.
The increment and decrement operators can change before and after the variable participates in the calculation.
Putting it in the front is to change first, and then calculate.
Putting it in the back is to calculate first, and then change.
Example | the value of the expression | change in a |
---|---|---|
++a | a+1 | +1 |
a++ | a | +1 |
–a | a-1 | -1 |
a– | a | -1 |
a++ and ++a: both increase the value of a by one, but the value of the expression is different.
a– and –a: both decrease the value of a by one, but the expressions have different values.
condition
Returns the left side of the colon if the expression holds.
Otherwise return to the right.
int a = 1 ? 2 : 3;
If 1 is true, a will be assigned the value 2.
#include<stdio.h>
int main(){
int a = 1 ? 2 : 3;
printf("%d\n",a);
return 0;
}
Effect: