0% found this document useful (0 votes)
26 views2 pages

Leupi - C Cheatsheet Inc C 2011

This document provides a concise C++ cheat sheet covering: 1) Standard data types and their ranges, bitwise operators, pointers, literals, and preprocessor directives 2) Common operators like arithmetic, assignment, comparison, logical, and bitshift 3) Multithreading concepts like thread creation and synchronization 4) Range-based for loops for iterating over containers

Uploaded by

Damian Hickey
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)
26 views2 pages

Leupi - C Cheatsheet Inc C 2011

This document provides a concise C++ cheat sheet covering: 1) Standard data types and their ranges, bitwise operators, pointers, literals, and preprocessor directives 2) Common operators like arithmetic, assignment, comparison, logical, and bitshift 3) Multithreading concepts like thread creation and synchronization 4) Range-based for loops for iterating over containers

Uploaded by

Damian Hickey
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 Bitwise Operators Pointers: Quick and dirty

int8_t -128 to 127 & Bitwise AND & Gets RAM adress of Variab​le(to save

uint8_t 0 to 255 | Bitwise OR into pointer)

* Derefe​rences pointe​r(r​eturns it´s


int16_t -32768 to 32767 ^ Bitwise XOR
content) or defines a variable to be a
uint16_t 0 to 65535 ~ Bitwise NOT
pointer
int32_t -21474​83648 to 2147483647 << Shift left
-> Access pointer class member. same
uint32_t 0 to 4294967295 >> Shift right as (*poin​ter​).m​ember()
int64_t -9.2 * 1018 to 9.2 * 1018 new Create new object on heap, returns
Boolean Logic pointer to object
uint64_t 0 to 1.8 * 1019
== Test of equality delete Remove object at the pointer on heap

Literals & Co. != Test of non-eq​uality Pointers allocate space on heap, normal

255 Integer < Less than variables on stack!

0xaf Hexade​cimal Integer > Greater than


using replaces typedef
1234.0 double <= Less than or equal
//typedef is deprecated
234.243f float >= Greater than or equal
typedef uint32_t uint32;
true bool ! NOT //now: using directive!
"​Hello World" string​/c-​string && AND //using identifier = type_name;
using uint32 = uint32_t;
'a' char || OR

Boolean expres​sions in C++ are evaluated left-


Auto Datatype
Prepro​cessor t​o-r​ight!
//auto is an automatic datatype:
#include Includes standard header file
Basic Operators int x = 4; //equals:
<LI​B> LIB
auto y = 4;
#include Includes Header.h file + addition //works for most cases, esp. STL:
"​Hea​der.h" - subtra​ction for(st​d::​vec​tor​<in​t>:​:It​erator it = v.begi​n().....)
#define PI Defines Easy Macro //with auto:
* multip​lic​ation
3.1415​9265359 for(auto it = v.begin; it != v.end(); ++it)
/ division
#define f(a,b) More Complex Macro
% modulo Compil​e-time assertion check
a+b
++var increase before
#undef PI Remove Definition static assert​(bo​ol_​con​stexpr, string)
evaluation
#ifdef PI Checks for defini​tion, if true,
var++ increase after Multit​hre​ading
code will be compiled
evaluation
#else Else part of the above if- //Thread Creation & Manage​ment:
condition ? result : short form of if-like
sta​tement void thread​_fu​nc(int a)
altern​ative; structure
#endif Ends the if-sta​tement {
:: Scope Operator std::cout << "My Number is: " << a;
-> pointe​r-t​o-m​ember }
Nullpo​inter
main()
. Access member
int* pInt; {
//old, deprec​ated: << >> Bitshi​ft(with streams: std::t​hread t1(thr​ead​_fu​nc(1));
if(pInt == NULL) input/​output) t1.join();
//new:
if(pInt == nullptr)
//still valid:
if(!pInt)

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/

Multit​hre​ading (cont)

}
//Sync​hro​niz​ation via:
std::m​ute​x.l​ock();
std::m​ute​x.u​nlo​ck();

Range based loops

//Easy range based loop:


std::v​ect​or<​int> vec = .....;
for(int i : vec) //foreach i in vec
//Same with auto:
const auto vi = ....;
for(auto i : vi)

Works with all Containers with begin() and end()

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