0% found this document useful (0 votes)
117 views

C++ Cheatsheet (Inc. C++2011) Cheat Sheet: by Via

This document is a C++ cheat sheet that summarizes standard system types and their ranges, null pointers, basic operators, literals, the preprocessor, boolean logic, pointers, auto datatype, static assertions, and multithreading in C++. It provides the basic building blocks of C++ including fundamental data types, operators, literals, preprocessor directives, and pointers. It also covers newer C++ features such as nullptr, auto type deduction, and multithreading.

Uploaded by

uuuuuuuuu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

C++ Cheatsheet (Inc. C++2011) Cheat Sheet: by Via

This document is a C++ cheat sheet that summarizes standard system types and their ranges, null pointers, basic operators, literals, the preprocessor, boolean logic, pointers, auto datatype, static assertions, and multithreading in C++. It provides the basic building blocks of C++ including fundamental data types, operators, literals, preprocessor directives, and pointers. It also covers newer C++ features such as nullptr, auto type deduction, and multithreading.

Uploaded by

uuuuuuuuu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ Cheatsheet(inc.

C++2011) Cheat Sheet


by Leupi via cheatography.com/5907/cs/1197/

Standard Sytemtypes and their range Nullpointer Basic Operators

int8_t -128 to 127 int* pInt; + addition

uint8_t 0 to 255 //old, deprecated: - subtraction


if(pInt == NULL)
int16_t -32768 to 32767 * multiplication
//new:
uint16_t 0 to 65535 if(pInt == nullptr) / division

int32_t -2147483648 to 2147483647 //still valid: % modulo


if(!pInt)
uint32_t 0 to 4294967295 ++var increase before

int64_t -9.2 * 1018 to 9.2 * 1018 evaluation


Bitwise Operators
uint64_t 0 to 1.8 * 1019 var++ increase after
& Bitwise AND evaluation
| Bitwise OR condition ? result : short form of if-like
Literals & Co.
^ Bitwise XOR alternative; structure
255 Integer
~ Bitwise NOT :: Scope Operator
0xaf Hexadecimal Integer
<< Shift left -> pointer-to-member
1234.0 double
>> Shift right . Access member
234.243f float
<< >> Bitshift(with streams:
true bool input/output)
Boolean Logic
"Hello World" string/c-string
== Test of equality
'a' char Pointers: Quick and dirty
!= Test of non-equality
& Gets RAM adress of Variable(to save
< Less than
Preprocessor into pointer)
> Greater than
#include Includes standard header file * Dereferences pointer(returns its
<LIB> LIB <= Less than or equal content) or defines a variable to be a

#include Includes Header.h file >= Greater than or equal pointer

"Header.h" ! NOT -> Access pointer class member. same


as (*pointer).member()
#define PI Defines Easy Macro && AND
3.14159265359 new Create new object on heap, returns
|| OR
#define f(a,b) More Complex Macro pointer to object
Boolean expressions in C++ are evaluated left-
a+b delete Remove object at the pointer on heap
to-right!
#undef PI Remove Definition Pointers allocate space on heap, normal
#ifdef PI Checks for definition, if true, variables on stack!
code will be compiled

#else Else part of the above if-


statement

#endif Ends the if-statement

By Leupi Published 18th August, 2013. Sponsored by Readability-Score.com


cheatography.com/leupi/ Last updated 18th August, 2013. Measure your website readability!
Page 1 of 2. https://readability-score.com
C++ Cheatsheet(inc. C++2011) Cheat Sheet
by Leupi via cheatography.com/5907/cs/1197/

using replaces typedef Range based loops

//typedef is deprecated //Easy range based loop:


typedef uint32_t uint32; std::vector<int> vec = .....;
//now: using directive! for(int i : vec) //foreach i in vec
//using identifier = type_name; //Same with auto:
using uint32 = uint32_t; const auto vi = ....;
for(auto i : vi)
Auto Datatype Works with all Containers with begin() and
//auto is an automatic datatype: end()
int x = 4; //equals:
auto y = 4;
//works for most cases, esp. STL:
for(std::vector<int>::Iterator it = v.begin().....)
//with auto:
for(auto it = v.begin; it != v.end(); ++it)

Compile-time assertion check

static assert(bool_constexpr, string)

Multithreading

//Thread Creation & Management:


void thread_func(int a)
{
std::cout << "My Number is: " << a;
}
main()
{
std::thread t1(thread_func(1));
t1.join();
}
//Synchronization via:
std::mutex.lock();
std::mutex.unlock();

By Leupi Published 18th August, 2013. Sponsored by Readability-Score.com


cheatography.com/leupi/ Last updated 18th August, 2013. Measure your website readability!
Page 2 of 2. https://readability-score.com

You might also like