\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{codinghippo} \pdfinfo{ /Title (215final.pdf) /Creator (Cheatography) /Author (codinghippo) /Subject (215final Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{6C9AA3} \definecolor{LightBackground}{HTML}{F5F8F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{215final Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{codinghippo} via \textcolor{DarkBackground}{\uline{cheatography.com/216746/cs/47450/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}codinghippo \\ \uline{cheatography.com/codinghippo} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 4th December, 2025.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Doubles/floats}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Range of +/- 1.7e308} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- 16 digits of precision} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Overflow = +/- inf, underflow = 0} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- Double = 8b, float = 4b} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Floats are less precise, used in Arduino} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Integers}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Max value is +/-2147483647} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- 2 or 4 bytes} \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Vari changes}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Short int x: half the byte size of int (half range)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- Long int x: double byte size of int (double range)} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Unsigned: positive numbers (double range)} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Usually double, int, void (depends on what you want to return)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- type \_name(what it inputs)\{\}} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Arduino}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- void setup () is used to initialized variables and configurations} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- pinMode (pin1, OUTPUT) means that the pin will have a output role} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Serial.begin(115200) initializes for print out} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- void loop () runs the code repeatedly, like while(1)} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- use float instead of double} \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- digitalWrite(pin1, HIGH) sets the pin to have 5V} \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Serial.print( ) will print to the IDE} \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- micros()*1.0e-6 is time in s} \tn % Row Count 11 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- digital is 0V or 5V, analog is continuous} \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.9908 cm} x{2.9862 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Arrays/dynamic}} \tn % Row 0 \SetRowColor{LightBackground} - Always starts at 0 & - Dynamic array is only for 1D \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{- 2D arrays: A{[}row{]}{[}column{]}} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{- Size must be an int} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{- A{[}{]} is allowed, not A{[}{]}{[}{]}} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{- A{[}i{]}++; means increase the value of A{[}i{]} by 1} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Dynamic array: \newline double *A; \newline int n; // which we'll use for input \newline A = new double {[}n{]}; \newline if(A == NULL)\{ \newline // check if it exists and can run code \newline cout \textless{}\textless{} "\textbackslash{}nerror in dynamic allocation"; \newline exit(1); \newline \} \newline delete{[}{]} A; \newline A = nullptr;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.9908 cm} x{2.9862 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Char/strings}} \tn % Row 0 \SetRowColor{LightBackground} - Used for strings & - String is char array \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} - Max range of -128/127 & - '\textbackslash{}0' is the term char \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} - char a = ''a'' & - For space, ' ' \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} & - Always make char size 100 or 1000 \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Reverse string: \newline void string\_reverse(char str1{[}{]}, char str2{[}{]})\{ \newline int i=0; \newline int counter=0; \newline \newline while(str1{[}i{]} != '\textbackslash{}0')\{ \newline counter++; \newline i++; // this finds string length \newline \} \newline \newline for (i=0;i\textless{}counter;i++)\{ \newline str2{[}i{]} = str1{[}counter -1 -i{]}; // because at counter its '\textbackslash{}0' \newline \} \newline str2{[}counter{]} = '\textbackslash{}0'; // to stop the string \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Files}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- ofstream fout // writing to file} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- ifstream fin // reading file} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- fout.close() at end of file part} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- create file: fout.open(".txt")} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- have \#include \textless{}fstream\textgreater{}} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Check error: \newline if (!fout or !fin)\{ \newline cout \textless{}\textless{} "\textbackslash{}nerror with file"; \newline exit(1); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Pointers}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Can store anything (int, double, function, etc)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- int*b checks what's inside b} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- p = \&b means p is b's address} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- *(\&b)=b is simply the address of b} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- *p=11 means there's 11 stored inside b} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- *(p+1) increments the pointer} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- *p +1 increments what's inside p} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- For char, it prints everything after the address} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- For double it prints what's at the specific address} \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.68758 cm} x{2.28942 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Special info}} \tn % Row 0 \SetRowColor{LightBackground} - Break to stop loop & - Bool has 1 = true and 0 = false \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} - Exit(0) to stop program & - \&\& means and \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} - Dot product: sum+= A{[}i{]} * B{[}i{]} & - || means or \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} - cout \textless{}\textless{}scientific \textless{}\textless{} setprecision(9) & - sizeof(int) =4 \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} - sizeof(double) = 8 & - sizeof (bool) = 1 \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{- sizeof(float)=4} \tn % Row Count 11 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Call by reference: \newline \&x means that it brings changes to main, not a copy of x} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Examples}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Transpose: \newline for (i=0;i\textless{}3;i++)\{ \newline for (j=0;j\textless{}3;j++)\{ \newline tA{[}i{]}{[}j{]} = A{[}j{]}{[}i{]}; \newline Dynamic array: \newline double {\emph{p1; \newline n = 10 or cin \textgreater{}\textgreater{} n; \newline p1 = new double {[}n{]}; \newline if (p1 == NULL) return 1; \newline delete p1; \newline No\_space: \newline void no\_space ( char str1 {[}{]}) \{ \newline int i, newsize=0; \newline for (i=0; str1{[}i{]}; i++)\{ \newline if (str1{[}i{]}!=' ')\{ \newline str1{[}newsize{]}=str1{[}i{]}; \newline newsize++; \newline \} \newline \} \newline str1{[}newsize{]}='\textbackslash{}0'; \newline \} \newline Alternating string: \newline j = 0; \newline for(i=0;i\textless{}n\_min;i++) \{ \newline str3{[}j{]} = str1{[}i{]}; j++; \newline str3{[}j{]} = str2{[}i{]}; j++; \newline \} \newline for(i=n\_min;i\textless{}n\_max;i++) \{ \newline if(n\_max == n1) str3{[}j{]} = str1{[}i{]}; \newline else str3{[}j{]} = str2{[}i{]}; j++; \newline \} \newline str3{[}j{]} = '\textbackslash{}0'; \newline \newline Arduino example: \newline \newline float t0, t, v = 30; \newline int p; \newline int input0; \newline float v0; \newline // a) \newline servo1.attach(3); \newline servo1.write(0); \newline delay(1000); // wait for the servo \newline // b) (30 deg / s) \newline t0 = micros()}}1.0e-6; // initial time \newline // p = p0 + v{\emph{(delta\_t) = p0 + v}}(t-t0) \newline // trajectory \newline while(1) \{ \newline t = micros(){\emph{1.0e-6; \newline p = v}}(t-t0); // trajectory \newline servo1.write(p); \newline if(p \textgreater{}= 90) break; \newline \} \newline while(1) \{ \newline input0 = analogRead(A0); \newline v0 = (input0/1023.0)*5; \newline // convert int to volts \newline if(v0 \textgreater{} 3) break; \newline \} \newline servo1.write(0); \newline delay(1000); \newline exit(0); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}