\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{Ruan} \pdfinfo{ /Title (cs50.pdf) /Creator (Cheatography) /Author (Ruan) /Subject (CS50 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}{0388A3} \definecolor{LightBackground}{HTML}{EFF7F9} \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{CS50 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Ruan} via \textcolor{DarkBackground}{\uline{cheatography.com/126499/cs/24505/}}} \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}Ruan \\ \uline{cheatography.com/ruan} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 28th September, 2020.\\ Updated 28th September, 2020.\\ 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}{Project base}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// include Standard Input and Output \newline \#include \textless{}stdio.h\textgreater{} \newline // include CS 50 helper \newline \#include \textless{}cs50.h\textgreater{} \newline \newline int main(void) \newline \{ \newline // Asks for the user name \newline string name = get\_string("What is your name? "); \newline // Print the message \newline printf("hello, \%s.\textbackslash{}n", name); \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}{Declaring variables}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// Variables declaration \newline // The structure to declare variables is: \newline // type variable\_name; \newline \newline int my\_integer; \newline char my\_single\_char; \newline bool true\_or\_false; \newline string a\_long\_string; \newline float price; \newline \newline // you can also declare multiple vars of the same type in one line \newline string first, last, full; \newline int total, a, b; \newline \newline \newline // assign "=" values to a variable \newline \newline my\_integer = 10; \newline my\_single\_char = 'A'; \newline true\_or\_false = true; \newline a\_long\_string = "A really long text"; \newline price = 1.25; \newline // note: When working with strings the value needs to be under double quotes " \newline // When working with chars the value needs to be under single quotes ' \newline \newline // intialization \newline int my\_age = 30; \newline float product\_price = 123.45; \newline string message = "thank you"; \newline char letter = 'A';} \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}{Conditional statements}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{if (boolean-expression) \newline \{ \newline // code if true \newline \} \newline \newline // -{}-{}-{}-{}-{}- \newline \newline if (boolean-expression) \newline \{ \newline // code if true \newline \} \newline else \newline \{ \newline //code if false \newline \} \newline \newline // -{}-{}-{}-{}-{}- \newline if (boolean-expression) \newline \{ \newline // code if true \newline \} \newline else if \seqsplit{(another-boolean-expression)} \newline \{ \newline //code if first is false but second is true \newline \} \newline else \newline \{ \newline //code if all are false \newline \} \newline \newline //-{}- \newline // Example ok ?: use \newline int x; \newline if (boolean-expression) \newline \{ \newline x = 5; \newline \} \newline else \newline \{ \newline x = 10; \newline \} \newline // this is a short form of the same code above \newline int x = boolean-expression ? 5 : 10; \newline \newline //-{}-{}-{}-{}-{}-{}-- \newline \newline int my\_number = 10; \newline switch(my\_number) \newline \{ \newline case 1: \newline printf("Number is 1"); \newline break; \newline case 10: \newline printf("Number is 10"); \newline break; \newline default: \newline printf("Number is invalid"); \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}{Loops}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{while (boolean-expression) \newline \{ \newline // code will be executed while the boolean-expression is true \newline \} \newline \newline \newline do \newline \{ \newline // do-while will always execute at least once. \newline // code will be executed while the boolean-expression is true \newline \} \newline while (boolean-expression); \newline \newline \newline for (initilization ; boolean-expression ; increment) \newline \{ \newline \newline \} \newline \newline for (int index = 0 ; index \textless{} 20 ; index ++) \newline \{ \newline \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.64701 cm} x{4.32999 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Data Types}} \tn % Row 0 \SetRowColor{LightBackground} int & Integers - 4 bytes (32 bits) \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} char & Single characters - 1 byte (8 bits) \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} float & Real numbers - 4 bytes (32 bits) \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{double} & Double precision for floats \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} void & Is a type but not a Data Type. Used in functions to say that params or returns are not required \tn % Row Count 9 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{CS50 ones} \tn % Row Count 10 (+ 1) % Row 6 \SetRowColor{LightBackground} bool & Boolean value (true or false) \tn % Row Count 11 (+ 1) % Row 7 \SetRowColor{white} \seqsplit{string} & Serie of characters (words, sentences, etc) \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.64701 cm} x{4.32999 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Arithmetic Operators}} \tn % Row 0 \SetRowColor{LightBackground} + & Sum (add) \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} - & Subtraction \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} * & Multiplication \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} / & Division \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \% & Module, gets the remainder (15 \% 7 == 1) \tn % Row Count 6 (+ 2) % Row 5 \SetRowColor{white} x++ & x = x + 1 \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} x-{}- & x = x - 1 \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} x += 5 & x = x + 5 \tn % Row Count 10 (+ 2) % Row 8 \SetRowColor{LightBackground} x *=5 & x = x * 5 \tn % Row Count 11 (+ 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}{Boolean expressions}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Boolean expression is used in C to compare values. \newline % Row Count 2 (+ 2) There are just two possible values for it {\bf{true}} or {\bf{false}}. \newline % Row Count 4 (+ 2) On boolean expressions, anything other than {\bf{false, 0 or NULL}} is considered as {\bf{true}}. \newline % Row Count 6 (+ 2) Logical operators: \newline % Row Count 7 (+ 1) \&\& - {\bf{AND}} is true only if both operands are true, otherwise false \newline % Row Count 9 (+ 2) || - {\bf{OR}} is false only if both operands are false, otherwise true \newline % Row Count 11 (+ 2) ! - {\bf{NOT}} inverts the value of its operand. \newline % Row Count 12 (+ 1) Relational operators \newline % Row Count 13 (+ 1) == - {\bf{EQUAL}} is true only if both operands are equal. \newline % Row Count 15 (+ 2) != - {\bf{NOT EQUAL}} is true if the operands are not equal. \newline % Row Count 17 (+ 2) \textless{} - {\bf{LESS THAN}} is true if the left operand is less than the one in the right. \newline % Row Count 19 (+ 2) \textgreater{} - {\bf{GREATER THAN}} is true if the left operand is greater than the one in the right. \newline % Row Count 21 (+ 2) \textgreater{}= - {\bf{GREATER THAN OR EQUAL TO}} is true if the left operand is greater than or equal to the one in the right. \newline % Row Count 24 (+ 3) \textless{}= - {\bf{LESS THAN OR EQUAL TO}} is true if the left operand is less or equal than the one in the right.% Row Count 27 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.28942 cm} x{2.68758 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{cs50.h Functions}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{get\_char("MESSAGE")} & prompts user for a char \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{get\_double("MESSAGE")} & prompts user for a double \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{get\_float("MESSAGE")} & prompts user for a float \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{get\_int("MESSAGE")} & prompts user for an int \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{get\_long("MESSAGE")} & prompts user for an long \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{get\_string("MESSAGE")} & prompts user for a string \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{1.19002 cm} p{1.46464 cm} x{1.92234 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Truth table}} \tn % Row 0 \SetRowColor{LightBackground} & AND \&\& & \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} x & y & (x \&\& y) \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} true & true & true \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} true & false & false \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} false & true & false \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} false & false & false \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} & OR || & \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} x & y & (x || y) \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} true & true & true \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} true & false & true \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} false & true & true \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} false & false & false \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Linux commands}} \tn % Row 0 \SetRowColor{LightBackground} make file\_name & Complile the code \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} ./file\_name & Execute a compiled file \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} cd folder\_name & Change directory \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} cd & Go back to the home folder (\textasciitilde{}) \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} cp original\_file copied\_file & Copy file \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} ls & List files \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} mkdir \seqsplit{name\_of\_the\_folder} & Create a folder \tn % Row Count 11 (+ 2) % Row 7 \SetRowColor{white} pwd & show the current path \tn % Row Count 13 (+ 2) % Row 8 \SetRowColor{LightBackground} rm file\_name & Remove a file \tn % Row Count 14 (+ 1) % Row 9 \SetRowColor{white} rm -R folder & Remove a folder recursively \tn % Row Count 16 (+ 2) % Row 10 \SetRowColor{LightBackground} touch file\_name & Create a file \tn % Row Count 17 (+ 1) % Row 11 \SetRowColor{white} mv original\_file renamed\_file & Rename or move a file \tn % Row Count 19 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.69678 cm} x{4.28022 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{String scapes}} \tn % Row 0 \SetRowColor{LightBackground} \textbackslash{}n & New line \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \textbackslash{}r & Return \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textbackslash{}t & Tab \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \textbackslash{}" & Double quote \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \textbackslash{}\textbackslash{} & Backslash \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{more \seqsplit{http://www.lix.polytechnique}.fr/\textasciitilde{}liberti/public/computing/prog/c/C/FUNCTIONS/escape.html} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.84609 cm} x{4.13091 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Format String}} \tn % Row 0 \SetRowColor{LightBackground} \%c & Char \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \%s & String \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \%d || \%i & Int \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \%f & Double or float \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \%.\#f & Float (limit the output to \# decimal places) \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} \%\% & \% \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}