1、变量名中只能出现字母(a~z,A~Z)、数字(0-9)或下划线。
2、第一个字符不能是数字
3、不能是C++关键字,所谓关键字,即C++中已经定义好的有特殊含义的单词。
4、区分大小写。
C++ 关键字(reserved)
| A – C | D – P | R – Z |
|---|---|---|
alignas (C++11)alignof (C++11)andand_eqasmatomic_cancel (TM TS) atomic_commit (TM TS) atomic_noexcept (TM TS) auto (1) (2) (3) (4)bitandbitorboolbreakcasecatchcharchar8_t (C++20)char16_t (C++11)char32_t (C++11)class (1)complconcept (C++20)constconsteval (C++20)constexpr (C++11)constinit (C++20)const_castcontinueco_await (C++20)co_return (C++20)co_yield (C++20) | decltype (C++11)default (1)delete (1)dodoubledynamic_castelseenum (1)explicitexport (1) (3)extern (1)falsefloatfor (1)friendgotoif (2) (4)inline (1)intlongmutable (1)namespacenewnoexcept (C++11)notnot_eqnullptr (C++11)operator (4)oror_eqprivate (3)protectedpublic | reflexpr (reflection TS)register (2)reinterpret_castrequires (C++20)returnshortsignedsizeof (1)staticstatic_assert (C++11)static_caststruct (1)switchsynchronized (TM TS) templatethis (4)thread_local (C++11)throwtruetrytypedeftypeidtypenameunionunsignedusing (1)virtualvoidvolatilewchar_twhilexorxor_eq |