GitHub - Mortennobel - Cpp-Cheatsheet - Modern C++ Cheatsheet
GitHub - Mortennobel - Cpp-Cheatsheet - Modern C++ Cheatsheet
mortennobel / cpp-cheatsheet
Star Watch
master Go to file
View code
README.md
Preprocessor
https://github.com/mortennobel/cpp-cheatsheet 1/13
29/01/2021 GitHub - mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
Literals
Declarations
https://github.com/mortennobel/cpp-cheatsheet 2/13
29/01/2021 GitHub - mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
STORAGE Classes
Statements
https://github.com/mortennobel/cpp-cheatsheet 3/13
29/01/2021 GitHub - mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
try { a; }
catch (T t) { b; } // If a throws a T, then jump here
catch (...) { c; } // If a throws something else, jump here
Functions
int f(int x, int y); // f is a function taking 2 ints and returning int
void f(); // f is a procedure taking no arguments
void f(int a=0); // f() is equivalent to f(0)
f(); // Default return type is int
inline f(); // Optimize for speed
f() { statements; } // Function definition (must be global)
T operator+(T x, T y); // a+b (if type T) calls operator+(a, b)
T operator-(T x); // -a calls function operator-(a)
T operator++(int); // postfix ++ or -- (parameter ignored)
extern "C" {void f();} // f() was compiled in C
Function parameters and return values may be of any type. A function must either be
declared or defined before it is used. It may be declared first and defined later. Every
program consists of a set of a set of global variable declarations and a set of function
definitions (possibly in separate files), one of which must be:
argv is an array of argc strings from the command line. By convention, main returns
status 0 if successful, 1 or higher for errors.
Functions with different parameters may have the same name (overloading). Operators
except :: . .* ?: may be overloaded. Precedence order is not affected. New operators
may not be created.
Expressions
Operators are grouped by precedence, highest first. Unary operators and assignment
evaluate right to left. All others are left to right. Precedence does not affect order of
evaluation, which is undefined. There are no run time checks for arrays out of bounds,
invalid pointers, etc.
x * y // Multiply
x / y // Divide (integers round toward 0)
x % y // Modulo (result has sign of x)
x + y // Add, or \&x[y]
x - y // Subtract, or number of elements from *x to *y
x << y // x shifted y bits to left (x * pow(2, y))
x >> y // x shifted y bits to right (x / pow(2, y))
https://github.com/mortennobel/cpp-cheatsheet 5/13
29/01/2021 GitHub - mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
Classes
All classes have a default copy constructor, assignment operator, and destructor, which
perform the corresponding operations on each data member and each base class as shown
above. There is also a default no-argument constructor (required to create arrays) if the
class has no constructors. Constructors, assignment, and destructors do not inherit.
https://github.com/mortennobel/cpp-cheatsheet 6/13
29/01/2021 GitHub - mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
Templates
Namespaces
https://github.com/mortennobel/cpp-cheatsheet 7/13
29/01/2021 GitHub - mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
https://github.com/mortennobel/cpp-cheatsheet 8/13
29/01/2021 GitHub - mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
https://github.com/mortennobel/cpp-cheatsheet 9/13
29/01/2021 GitHub - mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
utility (pair)
https://github.com/mortennobel/cpp-cheatsheet 10/13
29/01/2021 GitHub - mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
s.erase(123);
cout << s.size(); // Number of elements in set
https://github.com/mortennobel/cpp-cheatsheet 12/13
29/01/2021 GitHub - mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
Releases
No releases published
Packages
No packages published
Contributors 3
Languages
C++ 100.0%
https://github.com/mortennobel/cpp-cheatsheet 13/13