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)and and_eq asm atomic_cancel (TM TS) atomic_commit (TM TS) atomic_noexcept (TM TS) auto (1) (2) (3) (4)bitand bitor bool break case catch char char8_t (C++20)char16_t (C++11)char32_t (C++11)class (1)compl concept (C++20)const consteval (C++20)constexpr (C++11)constinit (C++20)const_cast continue co_await (C++20)co_return (C++20)co_yield (C++20) | decltype (C++11)default (1)delete (1)do double dynamic_cast else enum (1)explicit export (1) (3)extern (1)false float for (1)friend goto if (2) (4)inline (1)int long mutable (1)namespace new noexcept (C++11)not not_eq nullptr (C++11)operator (4)or or_eq private (3)protected public | reflexpr (reflection TS)register (2)reinterpret_cast requires (C++20)return short signed sizeof (1)static static_assert (C++11)static_cast struct (1)switch synchronized (TM TS) template this (4)thread_local (C++11)throw true try typedef typeid typename union unsigned using (1)virtual void volatile wchar_t while xor xor_eq |