作为程序员,了解这些符号的英文名称和读法非常重要,尤其是在阅读英文文档或与国外同事交流时。
下面我将编程中最常用的符号分为几类,为你详细列出它们的名称(Name)、英文读法(How to Read),并附上常见用法示例。
1. 基础算术运算符 (Basic Arithmetic Operators)
| 符号 (Symbol) | 名称 (Name) | 英文读法 (How to Read) | 示例 (Example) |
|---|
+ | Plus Sign | plus | a + b (a plus b) |
- | Hyphen-Minus | minus | a - b (a minus b) |
* | Asterisk | asterisk 或 times | a * b (a asterisk b 或 a times b) |
/ | Forward Slash | slash 或 divided by | a / b (a slash b 或 a divided by b) |
% | Percent Sign | percent 或 modulus | a % b (a percent b 或 a modulus b) |
** | Double Asterisk | double asterisk 或 to the power of | a ** b (a to the power of b) |
2. 赋值与复合赋值运算符 (Assignment Operators)
| 符号 (Symbol) | 名称 (Name) | 英文读法 (How to Read) | 示例 (Example) |
|---|
= | Equals Sign | equals | a = 5 (a equals 5 或 a is assigned 5) |
+= | Plus Equals | plus equals | a += b (a plus equals b 或 a is increased by b) |
-= | Minus Equals | minus equals | a -= b (a minus equals b) |
*= | Asterisk Equals | asterisk equals | a *= b (a asterisk equals b) |
/= | Slash Equals | slash equals | a /= b (a slash equals b) |
%= | Percent Equals | percent equals | a %= b (a percent equals b) |
3. 比较运算符 (Comparison Operators)
| 符号 (Symbol) | 名称 (Name) | 英文读法 (How to Read) | 示例 (Example) |
|---|
== | Double Equals | double equals 或 equals equals | a == b (a equals b) |
!= | Exclamation Equals | not equals | a != b (a not equals b) |
< | Less-Than Sign | less than | a < b (a less than b) |
> | Greater-Than Sign | greater than | a > b (a greater than b) |
<= | Less-Than or Equals | less than or equal to | a <= b (a less than or equal to b) |
>= | Greater-Than or Equals | greater than or equal to | a >= b (a greater than or equal to b) |
4. 逻辑运算符 (Logical Operators)
| 符号 (Symbol) | 名称 (Name) | 英文读法 (How to Read) | 示例 (Example) |
|---|
&& | Double Ampersand | double ampersand 或 AND | a && b (a AND b) |
|| | Double Vertical Bar | double pipe 或 OR | a || b (a OR b) |
! | Exclamation Mark | exclamation mark 或 NOT | !a (NOT a) |
5. 位运算符 (Bitwise Operators)
| 符号 (Symbol) | 名称 (Name) | 英文读法 (How to Read) | 示例 (Example) |
|---|
& | Ampersand | ampersand 或 bitwise AND | a & b (a bitwise AND b) |
| | Vertical Bar | pipe 或 bitwise OR | a | b (a bitwise OR b) |
^ | Caret | caret 或 bitwise XOR | a ^ b (a bitwise XOR b) |
~ | Tilde | tilde 或 bitwise NOT | ~a (bitwise NOT a) |
<< | Double Less-Than | double less-than 或 left shift | a << 2 (a left shift 2) |
>> | Double Greater-Than | double greater-than 或 right shift | a >> 2 (a right shift 2) |
6. 括号与分隔符 (Parentheses and Separators)
| 符号 (Symbol) | 名称 (Name) | 英文读法 (How to Read) | 示例 (Example) |
|---|
() | Parentheses | parentheses (singular: parenthesis) | (a + b) (parentheses a plus b parentheses) |
[] | Square Brackets | square brackets | array[0] (array square bracket 0 square bracket) |
{} | Curly Braces | curly braces 或 braces | { ... } (open brace … close brace) |
; | Semicolon | semicolon | int a; (int a semicolon) |
, | Comma | comma | a, b (a comma b) |
. | Period / Dot | dot | object.method() (object dot method parentheses) |
: | Colon | colon | key: value (key colon value) |
? | Question Mark | question mark | condition ? a : b ( ternary operator: condition ? a : b) |
-> | Arrow | arrow | a -> b (a arrow b) |
7. 其他特殊符号 (Other Special Symbols)
| 符号 (Symbol) | 名称 (Name) | 英文读法 (How to Read) | 示例 (Example) |
|---|
# | Hash / Octothorpe | hash 或 pound sign | #include (hash include) |
// | Double Slash | double slash | // comment (double slash comment) |
/* */ | Slash Star | slash star … star slash | /* comment */ (slash star comment star slash) |
"" | Double Quotes | double quotes | "string" (double quotes string double quotes) |
'' | Single Quotes | single quotes | 'c' (single quote c single quote) |
\ | Backslash | backslash | \n (backslash n) |
_ | Underscore | underscore | my_variable (my underscore variable) |
@ | At Sign | at sign | @decorator (at decorator) |
$ | Dollar Sign | dollar sign | $variable (dollar variable) |
^ | Caret | caret | (在正则表达式中) ^start (caret start) |
* | Asterisk | asterisk | (在正则表达式中) a* (a asterisk) |
& | Ampersand | ampersand | (在 C/C++ 中) &var (address of var) |
* | Asterisk | asterisk | (在 C/C++ 中) *ptr (dereference ptr 或 pointer to ptr) |
如何练习和记忆?
- 边写边说:在写代码时,尝试用英文默念出符号的名称,比如写
for (int i = 0; i < 10; i++) 时,可以默念:for parenthesis int i equals zero semicolon i less than ten semicolon i plus plus parenthesis。
- 阅读英文文档:这是最自然的学习方式。当你看到
if (a !== b) 时,通过上下文你会知道它读作 if a is not equal to b。
- 制作小抄:把你最不熟悉的符号写在一张纸上,放在手边,随时查看。