A sorted C/C++ cheat sheet, regularly organized and placed here for convenient reference.
C++ Operator Precedence
Associativity |
Operator |
Function |
Usage |
Left |
:: |
Global Scope |
::name |
Left |
:: |
Class Scope |
class::name |
Left |
:: |
Namespace Scope |
namespace::name |
Left |
. |
Member Access |
object.member |
Left |
-> |
Member Access |
pointer->member |
Left |
[] |
Subscript |
expr[expr] |
Left |
() |
Function Call |
name(expr_list) |
Left |
() |
Type Constructor |
type(expr_list) |
Right |
++ |
Post-increment |
lvalue++ |
Right |
– |
Post-decrement |
lvalue– |
Right |
typeid |
Type ID |
typeid(type) |
Right |
typeid |
Runtime Type ID |
typeid(expr) |
Right |
explicit cast |
Type Conversion |
cast_name(expr) |
Right |
++ |
Pre-increment |
++lvalue |
Right |
– |
Pre-decrement |
–lvalue |
Right |
~ |
Bitwise NOT |
~expr |
Right |
! |
Logical NOT |
!expr |
Right |
- |
Unary Negation |
-expr |
Right |
+ |
Unary Positive |
+expr |
Right |
* |
Dereference |
*expr |
Right |
& |
Address-of |
&lvalue |
Right |
() |
Type Conversion |
(type)expr |
Right |
sizeof |
Size of Object |
sizeof expr |
Right |
sizeof |
Size of Type |
sizeof(expr) |
Right |
sizeof |
Size of Parameter Pack |
sizeof…(name) |
Right |
new |
Create Object |
new type |
Right |
new[] |
Create Array |
new type[size] |
Right |
delete |
Release Object |
delete expr |
Right |
delete[] |
Release Array |
delete[] expr |
Right |
noexcept |
Can throw exception |
noexcept(expr) |
Left |
->* |
Pointer to Member Access |
ptr->*ptr_to_member |
Left |
.* |
Pointer to Member Access |
obj.*ptr_to_member |
Left |
* |
Multiplication |
expr*expr |
Left |
/ |
Division |
expr/expr |
Left |
% |
Modulo (Remainder) |
expr%expr |
Left |
+ |
Addition |
expr+expr |
Left |
- |
Subtraction |
expr-expr |
Left |
<< |
Left Shift |
expr<<expr |
Left |
>> |
Right Shift |
expr>>expr |
Left |
< |
Less than |
expr<expr |
Left |
<= |
Less than or Equal |
expr<=expr |
Left |
> |
Greater than |
expr>expr |
Left |
>= |
Greater than or Equal |
expr>=expr |
Left |
== |
Equality |
expr==expr |
Left |
!= |
Inequality |
expr!=expr |
Left |
& |
Bitwise AND |
expr&expr |
Left |
^ |
Bitwise XOR |
expr^expr |
Left |
¦ |
Bitwise OR |
expr ¦ expr |
Left |
&& |
Logical AND |
expr && expr |
Left |
¦¦ |
Logical OR |
expr ¦¦ expr |
Right |
?: |
Conditional (Ternary Operator) |
expr?expr:expr |
Right |
= |
Assignment |
lvalue=expr |
Right |
*/,/=,%=,+=,-=,<<=,>>=,&=, ¦=,^= |
Compound Assignment |
lvalue+=expr etc. |
Right |
throw |
Throw Exception |
throw expr |
Right |
, |
Comma Operator |
expr,expr |
C++ Keywords
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. |