- 關鍵字
- 識別字
- 字面常數
- 運算子
關鍵字
關鍵字為具有語法功能的保留字 (reserved word) , C++ 的關鍵字共有 73 個,如以下列表
| and | const_cast | if | register | typedef |
| and_eq | default | inline | reinterpret_cast | typeid |
| asm | delete | int | return | typename |
| auto | do | long | short | union |
| bitand | double | mutable | signed | unsigned |
| bitor | dynamic_cast | namespace | sizeof | using |
| bool | else | new | static | virtual |
| break | enum | not | static_cast | void |
| case | explicit | not_eq | struct | volatile |
| catch | export | operator | switch | wchar_t |
| char | false | or | template | while |
| class | float | or_eq | this | xor |
| compl | for | private | throw | xor_eq |
| const | friend | protected | true | |
| continue | goto | public | try |
識別字
識別字為寫程式時依需求自行定義的名稱,包括變數 (variable) 、函數 (function) 、類別 (class) 等,皆為使用自行定義的識別字。識別字可由二十六個英文字母大寫 (A-Z) ,小寫 (a-z) ,以及底線符號 (_) 所組成,如下
| _ | ||||||||||||
| a | b | c | d | e | f | g | h | i | j | k | l | m |
| n | o | p | q | r | s | t | u | v | w | x | y | z |
| A | B | C | D | E | F | G | H | I | J | K | L | M |
| N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
這裡須留意,英文大寫及小寫字母是不同的。
字面常數
字面常數的意思就是字面上的意義,也就是說, 1234 就代表整數數值一千兩百三十四的意義,因此,所謂的字面常數就是直接寫進 C++ 程式原始碼的數值,依資料型態分類有
- 整數字面常數 (integer literals)
- 浮點數字面常數 (floating-point literals)
- 布林字面常數 (Boolean literals)
- 字元字面常數 (character literals)
- 字元字串字面常數 (character string literals)
運算子
C++ 提供多樣、功能完整的運算子,依運算子結合後運算的優先次序,如下列表
| 運算子 | 結合規則 | |
|---|---|---|
| 1 | :: | 左到右 |
| 2 | () | 左到右 |
| [] | ||
| -> | ||
| . | ||
| ++ | ||
| -- | ||
| dynamic_cast | ||
| static_cast | ||
| reinterpret_cast | ||
| const_cast | ||
| typeid | ||
| 3 | ! | 右到左 |
| not | ||
| ~ | ||
| compl | ||
| ++ | ||
| -- | ||
| - | ||
| + | ||
| * | ||
| & | ||
| sizeof | ||
| new | ||
| new [] | ||
| delete | ||
| delete [] | ||
| (type) | ||
| 4 | ->* | 左到右 |
| .* | ||
| 5 | * | 左到右 |
| / | ||
| % | ||
| 6 | + | 左到右 |
| - | ||
| 7 | << | 左到右 |
| >> | ||
| 8 | < | 左到右 |
| <= | ||
| > | ||
| >= | ||
| 9 | == | 左到右 |
| eq | ||
| != | ||
| not_eq | ||
| 10 | & | 左到右 |
| bitand | ||
| 11 | ^ | 左到右 |
| xor | ||
| 12 | | | 左到右 |
| bitor | ||
| 13 | && | 左到右 |
| and | ||
| 14 | || | 左到右 |
| or | ||
| 15 | ?: | 右到左 |
| 16 | = | 右到左 |
| += | ||
| -= | ||
| *= | ||
| /= | ||
| %= | ||
| &= | ||
| and_eq | ||
| ^= | ||
| xor_eq | ||
| |= | ||
| or_eq | ||
| <<= | ||
| >>= | ||
| 17 | throw | |
| 18 | , | 左到右 |
| 中英文術語對照 | |
|---|---|
| 關鍵字 | keyword |
| 識別字 | identifier |
| 字面常數 | literal constant |
| 運算子 | operator |
| 保留字 | reserved word |
| 變數 | variable |
| 函數 | function |
| 類別 | class |
| 整數字面常數 | integer literals |
| 浮點數字面常數 | floating-point literals |
| 布林字面常數 | Boolean literals |
| 字元字面常數 | character literals |
| 字元字串字面常數 | character string literals |
您可以繼續參考
基本概念
標記
基本資料型態
相關目錄
回 C++ 快速導覽
回 C++ 教材
回首頁
參考資料
C++ reference
cplusplus.com
Cprogramming.com C++ Tutorial
C++ Primer, Fourth Edition, Stanley B. Lippman...
本文於 2013 年 1 月更新
沒有留言:
張貼留言