นิยาม
Keywords คือคำที่ความหมายถูกกำหนดโดย Compiler แล้ว ไม่สามารถใช้เป็น identifier ได้ Keywords ประกอบด้วย reserved words และ predefined identifiers
Predefined Identifiers vs Reserved Words
- Predefined identifiers: ถูกกำหนดโดย compiler แต่ผู้ใช้สามารถเปลี่ยนความหมายได้ เช่น
mainสามารถประกาศตัวแปรชื่อ main ได้ - Reserved words: ไม่สามารถใช้เป็น identifier ได้เลย เช่น
else
จำนวนและกลุ่ม
- รวม 95 reserved words
- 32 คำมาจาก C
- 30 คำใหม่เฉพาะ C++
- 11 คำ alternative tokens สำหรับ character set ที่จำกัด
รายการ Keywords (บางส่วน จัดกลุ่ม)
| กลุ่ม | Keywords |
|---|---|
| Control flow | if, else, switch, case, default, for, while, do, break, continue, goto, return |
| Data types | int, char, float, double, bool, void, wchar_t, char16_t, char32_t |
| Modifiers | const, volatile, signed, unsigned, short, long, static, mutable, constexpr |
| Class/OOP | class, struct, union, public, private, protected, friend, virtual, this, operator |
| Memory | new, delete, sizeof, alignas, alignof |
| Exception | try, catch, throw, noexcept |
| Templates | template, typename, typedef, decltype |
| C++11/14/17/20 | auto, nullptr, override, final, static_assert, thread_local, concept, requires, co_await, co_return, co_yield |
| Alternative tokens | and, or, not, bitand, bitor, compl, xor, and_eq, or_eq, not_eq, xor_eq |
รายการเต็ม 95 คำ รวมถึงคำที่มีการระบุ version (since C++11, C++20, TS) ดูได้จากตารางในเนื้อหาเดิม