C++ Quick Reference / C++ Cheatsheet: Preprocessor
C++ Quick Reference / C++ Cheatsheet: Preprocessor
Based on Phillip M. Duxbury's C++ Cheatsheet and edited by Morten Nobel-Jørgensen. The
cheatsheet focus is on C++ - not on the library. C++11 additions is inspired by ISOCPP.org C++11
Cheatsheet).
PREPROCESSOR
LITERALS
STORAGE CLASSES
FUNCTIONS
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:
int main() { statements... } or
int main(int argc, char* argv[]) { statements... }
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))
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.
TEMPLATES
NAMESPACES
DEQUE (array/stack/queue)
deque is like vector<T>, but also supports:
UTILITY (Pair)