标识符与关键字
c/c++标识符
II 首字符不能是数字;
命名规则有三:I 只能是字母(A-Z和a-z)、数字(0-9)或下划(_)线组成;
II 首字符不能是数字;
III不能与已有关键字产生冲突。
当然,默认要求还有“见名知义”、“不能太长”、“避免使用数字”、“避免使用下划线开头,尤其为双下划线”……等等,规定:
标识符有字母大小写敏感特点,不过没有长度限制。
下边截图是《C++ Primer Plus 第六版 中文版》与此相关的信息:
接着介绍常见的关键字:
C和C++共有的关键字,32个:参考C关键字
auto double int struct break else long switch
case enum register typedef char extern return union
const float short unsigned continue for signed void
default goto sizeof volatile do if while static
C++关键字:参考C++关键字
asm do if return typedef auto double inline short typeid bool dynamic_cast int signed typename break else long sizeof union case enum mutable static unsigned catch explicit namespace static_cast using char export new struct virtual class extern operator switch void const false private template volatile const_cast float protected this wchar_t continue for public throw while default friend register true delete goto reinterpret_cast tryC++11 关键字共73个。
新增关键字:alignas、alignof、char16_t、char32_t、constexpr、decltype、noexcept、nullptr、static_assert、thread_local。[3]
auto 的意义改变。[4]
register 被视为过时的(可能在未来标准移除)。[5]
export 因为实现支持太少(仅Edison Design Group的前端支持),编译效率低下,取消原有意义(仍是关键字,但使用它的程序是错误的),改为保留给未来标准使用。
附图一张: