整理的一份C/C++的速查表,平时整理下放到这里来,供方便查询。
C++ Operator Precedence
结合律 | 运算符 | 功能 | 用法 |
---|---|---|---|
左 | :: | 全局作用域 | ::name |
左 | :: | 类作用域 | class::name |
左 | :: | 命名空间作用域 | namespace::name |
左 | . | 成员选择 | object.member |
左 | -> | 成员选择 | pointer->member |
左 | [] | 下标 | expr[expr] |
左 | () | 函数调用 | name(expr_list) |
左 | () | 类型构造 | type(expr_list) |
右 | ++ | 后置递增运算 | lvalue++ |
右 | – | 后置递减运算 | lvalue– |
右 | typeid | 类型ID | typeid(type) |
右 | typeid | 运行时类型ID | typeid(expr) |
右 | explicit cast | 类型转换 | cast_name |
右 | ++ | 前置递增运算 | ++lvalue |
右 | – | 前置递减运算 | –lvalue |
右 | ~ | 位求反 | ~expr |
右 | ! | 逻辑非 | !expr |
右 | - | 一元负号 | -expr |
右 | + | 一元正号 | +expr |
右 | * | 解引用 | *expr |
右 | & | 取地址 | &lvalue |
右 | () | 类型转换 | (type)expr |
右 | sizeof | 对象的大小 | sizeof expr |
右 | sizeof | 类型的大小 | sizeof(expr) |
右 | sizeof | 参数包的大小 | sizeof…(name) |
右 | new | 创建对象 | new type |
右 | new[] | 创建数组 | new type[size] |
右 | delete | 释放对象 | delete expr |
右 | delete[] | 释放数组 | delete[] expr |
右 | noexcept | 能否抛出异常 | noexcept(expr) |
左 | ->* | 指向成员选择的指针 | ptr->*ptr_to_member |
左 | .* | 指向成员选择的指针 | obj.*ptr_to_member |
左 | * | 乘法 | expr*expr |
左 | / | 除法 | expr/expr |
左 | % | 取模(取余) | expr%expr |
左 | + | 加法 | expr+expr |
左 | - | 减法 | expr-expr |
左 | << | 向左移位 | expr<<expr |
左 | >> | 向右移位 | expr>>expr |
左 | < | 小于 | expr<expr |
左 | <= | 小于等于 | expr<=expr |
左 | > | 大于 | expr>expr |
左 | >= | 大于等于 | expr==expr |
左 | == | 相等 | expr>=expr |
左 | != | 不相等 | expr!=expr |
左 | & | 位与 | expr&expr |
左 | ^ | 位异或 | expr^expr |
左 | ¦ | 位或 | expr ¦ expr |
左 | && | 逻辑与 | expr && expr |
左 | ¦¦ | 逻辑或 | expr ¦¦ expr |
右 | ?: | 条件(三目运算符) | expr?exper:expr |
右 | = | 赋值 | lvalue=expr |
右 | */,/=,%=,+=,-=,<<=,>>=,&=, ¦=,^= | 复合赋值 | lvalue+=expr等 |
右 | throw | 抛出异常 | throw expr |
右 | , | 逗号运算符 | expr,expr |
C++ Keywords
alignas (since C++11) |
else |
requires (concepts TS) |
---|---|---|
alignof (since C++11) |
enum |
return |
and |
explicit |
short |
and_eq |
export (1) |
signed |
asm |
extern |
sizeof |
auto (1) |
false |
static |
bitand |
float |
static_assert (since C++11) |
bitor |
for |
static_cast |
bool |
friend |
struct |
break |
goto |
switch |
case |
if |
template |
catch |
inline |
this |
char |
int |
thread_local (since C++11) |
char16_t (since C++11) |
long |
throw |
char32_t (since C++11) |
mutable |
true |
class |
namespace |
try |
compl |
new |
typedef |
concept (concepts TS) |
noexcept (since C++11) |
typeid |
const |
not |
typename |
constexpr (since C++11) |
not_eq |
union |
const_cast |
nullptr (since C++11) |
unsigned |
continue |
operator |
using (1) |
decltype (since C++11) |
or |
virtual |
default (1) |
or_eq |
void |
delete (1) |
private |
volatile |
do |
protected |
wchar_t |
double |
public |
while |
dynamic_cast |
register |
xor |
reinterpret_cast |
xor_eq |
Conversion Specifiers in C
Conversion | Output Specification |
---|---|
%a | Floating-point number, hexadecimal digits and p-notation (C99/C11). |
%A | Floating-point number, hexadecimal digits and P-notation (C99/C11). Exploring and Exploiting printf() and scanf() |
%c | Single character. |
%d | Signed decimal integer. |
%e | Floating-point number, e-notation. |
%E | Floating-point number, e-notation. |
%f | Floating-point number, decimal notation. |
%g | Use %f or %e , depending on the value. The %e style is used if the exponent is less than −4 or greater than or equal to the precision. |
%G | Use %f or %E , depending on the value. The %E style is used if the exponent is less than −4 or greater than or equal to the precision. |
%i | Signed decimal integer (same as |
%o | Unsigned octal integer. |
%p | A pointer. |
%s | Character string. |
%u | Unsigned decimal integer. |
%x | Unsigned hexadecimal integer, using hex digits 0f . |
%X | Unsigned hexadecimal integer, using hex digits 0F . |
%% | Prints a percent sign. |