C++關鍵字
關鍵字是指其含義已由編譯器預先定義的詞語。這些關鍵字不能用作識別符號。請注意,關鍵字是保留字和預定義識別符號的集合。預定義識別符號是由編譯器定義的識別符號,但其含義可以由使用者更改。
例如,您可以在主函式內宣告一個名為main的變數,對其進行初始化,然後列印其值(但僅這樣做是為了驗證您可以這樣做!)。另一方面,您不能對名為else的變數這樣做。區別在於else是保留字,而main“僅僅”是預定義識別符號。
C++共有95個保留字。C++的保留字可以方便地分為幾組。在第一組中,我們列出了那些也在C程式語言中出現並被帶入C++的保留字。共有32個這樣的保留字。
另外還有30個保留字在C中不存在,因此是C++程式語言的新增內容。
有11個C++保留字在使用標準ASCII字元集時並非必不可少,但它們已被新增以提供一些C++運算子的可讀替代方案,並方便使用缺少C++所需字元的字元集進行程式設計。
以下是所有這些保留字的列表:
| alignas (自C++11起) | double | reinterpret_cast |
| alignof (自C++11起) | dynamic_cast | requires (自C++20起) |
| and | else | return |
| and_eq | enum | short |
| asm | explicit | signed |
| atomic_cancel (TM TS) | export(1) | sizeof(1) |
| atomic_commit (TM TS) | extern(1) | static |
| atomic_noexcept (TM TS) | false | static_assert (自C++11起) |
| auto(1) | float | static_cast |
| bitand | for | struct(1) |
| bitor | friend | switch |
| bool | goto | synchronized (TM TS) |
| break | if | template |
| case | import (modules TS) | this |
| catch | inline(1) | thread_local (自C++11起) |
| char | int | throw |
| char16_t (自C++11起) | long | true |
| char32_t (自C++11起) | module (modules TS) | try |
| class(1) | mutable(1) | typedef |
| compl | namespace | typeid |
| concept (自C++20起) | new | typename |
| const | noexcept (自C++11起) | union |
| constexpr (自C++11起) | not | unsigned |
| const_cast | not_eq | using(1) |
| continue | nullptr (自C++11起) | virtual |
| co_await (coroutines TS) | operator | void |
| co_return (coroutines TS) | or | volatile |
| co_yield (coroutines TS) | or_eq | wchar_t |
| decltype (自C++11起) | private | while |
| default(1) | protected | xor |
| delete(1) | public | xor_eq |
| do | register(2) |
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP