C++ 标识符
C++ 标识符是用来标识变量、函数、类、模块,或任何其他用户自定义项目的名称。
一个标识符以字母 A-Z 或 a-z 或下划线 _ 开始,后跟零个或多个字母、下划线和数字(0-9)。识别符有效长度不超过247字符。C++ 标识符内不允许出现标点字符,比如 @、& 和 %。C++ 是区分大小写的编程语言。
C++ 关键字
这些保留字不能作为常量名、变量名或其他标识符名称。
alignas | do | reinterpret_cast |
alignof | double | requires (since C++20) |
and | dynamic_cast | return |
and_eq | else | short |
asm | enum | signed |
auto | explicit | sizeof |
bitand | export | static |
bitor | extern | static_assert |
bool | false | static_cast |
break | float | struct |
case | for | switch |
catch | friend | template |
char | goto | this |
char8_t | if | thread_local |
char16_t | inline | throw |
char32_t | int | true |
class | long | try |
compl | mutable | typedef |
concept (since C++20) | namespace | typeid |
const | new | typename |
consteval (since C++20) | noexcept | union |
constexpr | not | unsigned |
constinit (since C++20) | not_eq | using |
const_cast | nullptr | virtual |
continue | operator | void |
co_await (since C++20) | or | volatile |
co_return (since C++20) | or_eq | wchar_t |
co_yield (since C++20) | private | while |
decltype | protected | xor |
default | public | xor_eq |
delete | register |
1.alignas:
关键字用来设置内存中对齐方式,最小是8字节对齐,可以是16,32,64,128等。
2.alignof:
返回类型的对齐要求,
返回由类型标识所指示的类型的任何实例所要求的对齐字节数,该类型可以为完整对象类型、元素类型完整的数组类型或者到这些类型之一的引用类型。
若类型为引用类型,则运算符返回被引用类型的对齐;若类型为数组类型,则返回元素类型的对齐要求。
3.and
用在&&的替代写法
4.and_eq
用做&=替代写法
5.bitand
用作&的替代写法
6.bitor
用作|的替代写法
7.char8_t
UTF-8 字符表示的类型,要求大到足以表示任何 UTF-8 编码单元( 8 位)。它与unsigned char 具有相同的大小、符号性和对齐(从而char和signed char具有相同的大小和对齐),但它是独立的类型。(C++20)
8.char16_t
UTF-16 字符表示的类型,要求大到足以表示任何 UTF-16 编