Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

C++ Keywords (คีย์เวิร์ด)


นิยาม

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 flowif, else, switch, case, default, for, while, do, break, continue, goto, return
Data typesint, char, float, double, bool, void, wchar_t, char16_t, char32_t
Modifiersconst, volatile, signed, unsigned, short, long, static, mutable, constexpr
Class/OOPclass, struct, union, public, private, protected, friend, virtual, this, operator
Memorynew, delete, sizeof, alignas, alignof
Exceptiontry, catch, throw, noexcept
Templatestemplate, typename, typedef, decltype
C++11/14/17/20auto, nullptr, override, final, static_assert, thread_local, concept, requires, co_await, co_return, co_yield
Alternative tokensand, or, not, bitand, bitor, compl, xor, and_eq, or_eq, not_eq, xor_eq

รายการเต็ม 95 คำ รวมถึงคำที่มีการระบุ version (since C++11, C++20, TS) ดูได้จากตารางในเนื้อหาเดิม