\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{Ashlyn Black (Ashlyn Black)} \pdfinfo{ /Title (c-reference.pdf) /Creator (Cheatography) /Author (Ashlyn Black (Ashlyn Black)) /Subject (C Reference 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}{A31759} \definecolor{LightBackground}{HTML}{F9F0F4} \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{C Reference Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Ashlyn Black (Ashlyn Black)} via \textcolor{DarkBackground}{\uline{cheatography.com/20410/cs/3196/}}} \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}Ashlyn Black (Ashlyn Black) \\ \uline{cheatography.com/ashlyn-black} \\ \uline{\seqsplit{ashlynblack}.com} \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 January, 2015.\\ Updated 12th May, 2016.\\ 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*}{2} \begin{tabularx}{8.4cm}{x{1.872 cm} x{1.728 cm} x{1.872 cm} x{1.728 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{Number Literals}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{\{\{noshy\}\}{\bf{Integers}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{noshy\}\}`0b11111111` & \{\{noshy\}\}binary & \{\{noshy\}\}`0B11111111` & \{\{noshy\}\}binary \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \{\{noshy\}\}`0377` & \{\{noshy\}\}octal & \{\{noshy\}\}`255` & \{\{noshy\}\}decimal \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \{\{noshy\}\}`0xff` & \{\{noshy\}\}hexadecimal & \{\{noshy\}\}`0xFF` & \{\{noshy\}\}hexadecimal \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Real Numbers}}} \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{4}{x{8.4cm}}{\{\{noshy\}\}`88.0f` / `88.1234567f`} \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{single precision float ( `f` suffix )} \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{4}{x{8.4cm}}{\{\{noshy\}\}`88.0` / `88.123456789012345`} \tn % Row Count 13 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{double precision float ( no `f` suffix )} \tn % Row Count 14 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{4}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Signage}}} \tn % Row Count 15 (+ 1) % Row 10 \SetRowColor{LightBackground} \{\{noshy\}\}`42` / `+42` & positive & \{\{noshy\}\}`-42` & negative \tn % Row Count 18 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}----} \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}Binary notation `0b...` / `0B...` is available on GCC and most but not all C compilers.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Variables}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Declaring}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{nobreak\}\}`int x;` & \{\{noshy\}\}A variable. \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`char x = 'C';` & \{\{noshy\}\}A variable \& initialising it. \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`float x, y, z;` & \{\{noshy\}\}Multiple variables of the same type. \tn % Row Count 7 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{nobreak\}\}`const int x = 88;` & A constant variable: can't assign to after declaration (compiler enforced.) \tn % Row Count 11 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{{\bf{Naming}}} \tn % Row Count 12 (+ 1) % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}`johnny5IsAlive;`\{\{fa-check\}\} & \{\{noshy\}\}Alphanumeric, not a keyword, begins with a letter. \tn % Row Count 15 (+ 3) % Row 7 \SetRowColor{white} \{\{nobreak\}\}`\textasciitilde{}\textasciitilde{}2001\textasciitilde{}\textasciitilde{}ASpaceOddysey;`\{\{fa-times\}\} & \{\{noshy\}\}Doesn't begin with a letter. \tn % Row Count 18 (+ 3) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}`\textasciitilde{}\textasciitilde{}while\textasciitilde{}\textasciitilde{};`\{\{fa-times\}\} & \{\{noshy\}\}Reserved keyword. \tn % Row Count 20 (+ 2) % Row 9 \SetRowColor{white} \{\{nobreak\}\}`how\textasciitilde{}\textasciitilde{} exciting!\textasciitilde{}\textasciitilde{};`\{\{fa-times\}\} & \{\{noshy\}\}Non-alphanumeric. \tn % Row Count 23 (+ 3) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}`\textasciitilde{}\textasciitilde{}iamaverylongvariablenameohmygoshyesiam\textasciitilde{}\textasciitilde{};`\{\{fa-times\}\}} \tn % Row Count 25 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}Longer than 31 characters (C89 \& C90 only)} \tn % Row Count 27 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}Constants are `CAPITALISED`. Function names usually take the form of a verb eg. `plotRobotUprising()`.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.052 cm} x{2.736 cm} x{2.812 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Primitive Variable Types}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{*applicable but not limited to most ARM, AVR, x86 \& x64 installations}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{3}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`{[}class{]} {[}qualifier{]} {[}unsigned{]} type/void name;`} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{\{\{bt\}\}\{\{ac\}\}\{\{noshy\}\}{\emph{by ascending arithmetic conversion}}} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{3}{x{8.4cm}}{{\bf{Integers}}} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} {\emph{Type}} & {\emph{Bytes}} & {\emph{Value Range}} \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} \{\{noshy\}\}`char` & \{\{ac\}\}1 & \{\{noshy\}\}`unsigned` {\bf{OR}} `signed` \tn % Row Count 11 (+ 3) % Row 6 \SetRowColor{LightBackground} \{\{noshy\}\}`unsigned char` & \{\{ac\}\}1 & \{\{noshy\}\}0 to 2\textasciicircum{}8\textasciicircum{}-1 \tn % Row Count 14 (+ 3) % Row 7 \SetRowColor{white} \{\{noshy\}\}`signed char` & \{\{ac\}\}1 & \{\{noshy\}\}-2\textasciicircum{}7\textasciicircum{} to 2\textasciicircum{}7\textasciicircum{}-1 \tn % Row Count 17 (+ 3) % Row 8 \SetRowColor{LightBackground} \{\{noshy\}\}`int` & \{\{ac\}\}2 / 4 & \{\{noshy\}\}`unsigned` {\bf{OR}} `signed` \tn % Row Count 20 (+ 3) % Row 9 \SetRowColor{white} \{\{noshy\}\}`unsigned int` & \{\{ac\}\}2 / 4 & \{\{noshy\}\}0 to 2\textasciicircum{}16\textasciicircum{}-1 {\bf{OR}} 2\textasciicircum{}31\textasciicircum{}-1 \tn % Row Count 23 (+ 3) % Row 10 \SetRowColor{LightBackground} \{\{noshy\}\}`signed int` & \{\{ac\}\}2 / 4 & \{\{noshy\}\}-2\textasciicircum{}15\textasciicircum{} to 2\textasciicircum{}15\textasciicircum{}-1 {\bf{OR}} -2\textasciicircum{}31\textasciicircum{} to 2\textasciicircum{}32\textasciicircum{}-1 \tn % Row Count 27 (+ 4) % Row 11 \SetRowColor{white} \{\{noshy\}\}`short` & \{\{ac\}\}2 & \{\{noshy\}\}`unsigned` {\bf{OR}} `signed` \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.052 cm} x{2.736 cm} x{2.812 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Primitive Variable Types (cont)}} \tn % Row 12 \SetRowColor{LightBackground} \{\{noshy\}\}`unsigned short` & \{\{ac\}\}2 & \{\{noshy\}\}0 to 2\textasciicircum{}16\textasciicircum{}-1 \tn % Row Count 3 (+ 3) % Row 13 \SetRowColor{white} \{\{noshy\}\}`signed short` & \{\{ac\}\}2 & \{\{noshy\}\}-2\textasciicircum{}15\textasciicircum{} to 2\textasciicircum{}15\textasciicircum{}-1 \tn % Row Count 6 (+ 3) % Row 14 \SetRowColor{LightBackground} \{\{noshy\}\}`long` & \{\{ac\}\}4 / 8 & \{\{noshy\}\}`unsigned` {\bf{OR}} `signed` \tn % Row Count 9 (+ 3) % Row 15 \SetRowColor{white} \{\{noshy\}\}`unsigned long` & \{\{ac\}\}4 / 8 & \{\{noshy\}\}0 to 2\textasciicircum{}32\textasciicircum{}-1 {\bf{OR}} 2\textasciicircum{}64\textasciicircum{}-1 \tn % Row Count 12 (+ 3) % Row 16 \SetRowColor{LightBackground} \{\{noshy\}\}`signed long` & \{\{ac\}\}4 / 8 & \{\{noshy\}\}-2\textasciicircum{}31\textasciicircum{} to 2\textasciicircum{}31\textasciicircum{}-1 {\bf{OR}} -2\textasciicircum{}63\textasciicircum{} to 2\textasciicircum{}63\textasciicircum{}-1 \tn % Row Count 16 (+ 4) % Row 17 \SetRowColor{white} \{\{noshy\}\}`long long` & \{\{ac\}\}8 & \{\{noshy\}\}`unsigned` {\bf{OR}} `signed` \tn % Row Count 19 (+ 3) % Row 18 \SetRowColor{LightBackground} \{\{noshy\}\}`unsigned long long` & \{\{ac\}\}8 & \{\{noshy\}\}0 to 2\textasciicircum{}64\textasciicircum{}-1 \tn % Row Count 22 (+ 3) % Row 19 \SetRowColor{white} \{\{noshy\}\}`signed long long` & \{\{ac\}\}8 & \{\{noshy\}\}-2\textasciicircum{}63\textasciicircum{} to 2\textasciicircum{}63\textasciicircum{}-1 \tn % Row Count 25 (+ 3) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{\{\{bt\}\}{\bf{Floats}}} \tn % Row Count 26 (+ 1) % Row 21 \SetRowColor{white} {\emph{Type}} & {\emph{Bytes}} & {\emph{Value Range (Normalized)}} \tn % Row Count 28 (+ 2) % Row 22 \SetRowColor{LightBackground} \{\{noshy\}\}`float` & \{\{ac\}\}4 & \{\{noshy\}\}±1.2×10\textasciicircum{}-38\textasciicircum{} to ±3.4×10\textasciicircum{}38\textasciicircum{} \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.052 cm} x{2.736 cm} x{2.812 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Primitive Variable Types (cont)}} \tn % Row 23 \SetRowColor{LightBackground} \{\{noshy\}\}`double` & \{\{ac\}\}8 / 4 & \{\{noshy\}\}±2.3×10\textasciicircum{}-308\textasciicircum{} to ±1.7×10\textasciicircum{}308\textasciicircum{} {\bf{OR}} alias to `float` for AVR. \tn % Row Count 6 (+ 6) % Row 24 \SetRowColor{white} \{\{noshy\}\}`long double` & \{\{noshy\}\}ARM: 8, AVR: 4, x86: 10, x64: 16 & \tn % Row Count 9 (+ 3) % Row 25 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{\{\{bt\}\}{\bf{Qualifiers}}} \tn % Row Count 10 (+ 1) % Row 26 \SetRowColor{white} \{\{nobreak\}\}`const type` & \{\{noshy\}\}Flags variable as read-only (compiler can optimise.) & \tn % Row Count 15 (+ 5) % Row 27 \SetRowColor{LightBackground} \{\{nobreak\}\}`volatile type` & \{\{noshy\}\}Flags variable as unpredictable (compiler cannot optimise.) & \tn % Row Count 20 (+ 5) % Row 28 \SetRowColor{white} \mymulticolumn{3}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Storage Classes}}} \tn % Row Count 21 (+ 1) % Row 29 \SetRowColor{LightBackground} \{\{noshy\}\}`register` & Quick access required. May be stored in RAM {\bf{OR}} a register. Maximum size is register size. & \tn % Row Count 28 (+ 7) % Row 30 \SetRowColor{white} \{\{noshy\}\}`static` & Retained when out of scope. `static` global variables are confined to the scope of the compiled object file they were declared in. & \tn % Row Count 38 (+ 10) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.052 cm} x{2.736 cm} x{2.812 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Primitive Variable Types (cont)}} \tn % Row 31 \SetRowColor{LightBackground} \{\{noshy\}\}`extern` & Variable is declared by another file. & \tn % Row Count 3 (+ 3) % Row 32 \SetRowColor{white} \mymulticolumn{3}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Typecasting}}} \tn % Row Count 4 (+ 1) % Row 33 \SetRowColor{LightBackground} \{\{nobreak\}\}`(type)a` & \{\{noshy\}\}Returns `a` as data `type`. & \tn % Row Count 7 (+ 3) % Row 34 \SetRowColor{white} \mymulticolumn{3}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`char x = 1, y = 2; float z = (float) x / y;`} \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}Some types (denoted with {\bf{OR}}) are architecture dependant. \newline \newline There is no primitive boolean type, only zero (false, `0`) and non-zero (true, usually `1`.)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.672 cm} x{1.14 cm} x{4.788 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Extended Variable Types}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{\{\{bb\}\}\{\{ac\}\}`{[}class{]} {[}qualifier{]} type name;`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{3}{x{8.4cm}}{\{\{ac\}\}{\emph{by ascending arithmetic conversion}}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{{\bf{From the `stdint.h` Library}}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} {\emph{Type}} & {\emph{Bytes}} & {\emph{Value Range}} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{`int8\_t`} & 1 & -2\textasciicircum{}7\textasciicircum{} to 2\textasciicircum{}7\textasciicircum{}-1 \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \seqsplit{`uint8\_t`} & 1 & 0 to 2\textasciicircum{}8\textasciicircum{}-1 \tn % Row Count 8 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{`int16\_t`} & 2 & -2\textasciicircum{}15\textasciicircum{} to 2\textasciicircum{}15\textasciicircum{}-1 \tn % Row Count 10 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{`uint16\_t`} & 2 & 0 to 2\textasciicircum{}16\textasciicircum{}-1 \tn % Row Count 12 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{`int32\_t`} & 4 & -2\textasciicircum{}31\textasciicircum{} to 2\textasciicircum{}31\textasciicircum{}-1 \tn % Row Count 14 (+ 2) % Row 9 \SetRowColor{white} \seqsplit{`uint32\_t`} & 4 & 0 to 2\textasciicircum{}32\textasciicircum{}-1 \tn % Row Count 16 (+ 2) % Row 10 \SetRowColor{LightBackground} \seqsplit{`int64\_t`} & 8 & -2\textasciicircum{}63\textasciicircum{} to 2\textasciicircum{}63\textasciicircum{}-1 \tn % Row Count 18 (+ 2) % Row 11 \SetRowColor{white} \seqsplit{`uint64\_t`} & 8 & 0 to 2\textasciicircum{}64\textasciicircum{}-1 \tn % Row Count 20 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{{\bf{From the `stdbool.h` Library}}} \tn % Row Count 21 (+ 1) % Row 13 \SetRowColor{white} {\emph{Type}} & {\emph{Bytes}} & {\emph{Value Range}} \tn % Row Count 23 (+ 2) % Row 14 \SetRowColor{LightBackground} `bool` & 1 & `true` / `false` or `0` / `1` \tn % Row Count 25 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{\{\{ac\}\}The `stdint.h` library was introduced in C99 to give integer types architecture-independent lengths.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Structures}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Defining}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{noshy\}\}`struct strctName\{ type x; type y; \};` & \{\{noshy\}\}A structure type `strctName` with two members, `x` and `y`. {\emph{Note trailing semicolon}} \tn % Row Count 6 (+ 5) % Row 2 \SetRowColor{LightBackground} \{\{noshy\}\}`struct item\{ struct item *next; \};` & \{\{noshy\}\}A structure with a recursive structure pointer inside. Useful for linked lists. \tn % Row Count 11 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Declaring}}} \tn % Row Count 12 (+ 1) % Row 4 \SetRowColor{LightBackground} \{\{noshy\}\}`struct strctName varName;` & \{\{noshy\}\}A variable `varName` as structure type `strctName`. \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} \{\{noshy\}\}`struct strctName *ptrName;` & \{\{noshy\}\}A `strctName` structure type pointer, `ptrName`. \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} \{\{noshy\}\}`struct strctName\{ type a; type b; \} varName;` & \{\{noshy\}\}Shorthand for defining `strctName` and declaring `varName` as that structure type. \tn % Row Count 23 (+ 5) % Row 7 \SetRowColor{white} \{\{noshy\}\}`struct strctName varName = \{ a, b \};` & \{\{noshy\}\}A variable `varName` as structure type `strctName` and initialising its members. \tn % Row Count 28 (+ 5) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Accessing}}} \tn % Row Count 29 (+ 1) % Row 9 \SetRowColor{white} \{\{noshy\}\}`varName.x` & Member `x` of structure `varName`. \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Structures (cont)}} \tn % Row 10 \SetRowColor{LightBackground} \{\{nobreak\}\}`ptrName-\textgreater{}x` & Value of structure pointer `ptrName` member `x`. \tn % Row Count 3 (+ 3) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Bit Fields}}} \tn % Row Count 4 (+ 1) % Row 12 \SetRowColor{LightBackground} \{\{noshy\}\}`struct\{char a:4, b:4\} x;` & Declares `x` with two members `a` and `b`, both four bits in size (0 to 15.) \tn % Row Count 8 (+ 4) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Array members can't be assigned bit fields.}}} \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Type Definitions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{noshy\}\}{\bf{Defining}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{noshy\}\}`typedef unsigned short uint16;` & \{\{noshy\}\}Abbreviating a longer type name to `uint16`. \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \{\{noshy\}\}`typedef struct structName\{int a, b;\}newType;` & \{\{noshy\}\}Creating a `newType` from a structure. \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \{\{noshy\}\}`typedef enum typeName\{false, true\}bool;` & \{\{noshy\}\}Creating an enumerated `bool` type. \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Declaring}}} \tn % Row Count 11 (+ 1) % Row 5 \SetRowColor{white} \{\{noshy\}\}`uint16 x = 65535;` & Variable `x` as type `uint16`. \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} \{\{noshy\}\}`newType y = \{0, 0\};` & Structure `y` as type `newType`. \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Unions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{noshy\}\}{\bf{Defining}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{noshy\}\}`union uName\{int x; char y{[}8{]};\}` & \{\{noshy\}\}A union type `uName` with two members, `x` \& `y`. Size is same as biggest member size. \tn % Row Count 6 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Declaring}}} \tn % Row Count 7 (+ 1) % Row 3 \SetRowColor{white} \{\{noshy\}\}`union uN vName;` & \{\{noshy\}\}A variable `vName` as union type `uN`. \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Accessing}}} \tn % Row Count 11 (+ 1) % Row 5 \SetRowColor{white} \{\{noshy\}\}`vName.y{[}int{]}` & Members cannot store values concurrently. Setting `y` will corrupt `x`. \tn % Row Count 15 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}Unions are used for storing multiple data types in the same area of memory.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.84 cm} x{4.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Enumeration}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{noshy\}\}{\bf{Defining}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{noshy\}\}`enum bool \{ false, true \};` & \{\{noshy\}\}A custom data type `bool` with two possible states: `false` or `true`. \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Declaring}}} \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} \{\{noshy\}\}`enum bool varName;` & A variable `varName` of data type `bool`. \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Assigning}}} \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} \{\{noshy\}\}`varName = true;` & Variable `varName` can only be assigned values of either `false` or `true`. \tn % Row Count 14 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Evaluating}}} \tn % Row Count 15 (+ 1) % Row 7 \SetRowColor{white} \{\{noshy\}\}`if(varName == false)` & Testing the value of `varName`. \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.12 cm} x{4.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pointers}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{noshy\}\}{\bf{Declaring}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{noshy\}\}`type *x;` & \{\{noshy\}\}Pointers have a data `type` like normal variables. \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \{\{noshy\}\}`void *v;` & \{\{noshy\}\}They can also have an incomplete type. Operators other than assignment cannot be applied as the length of the type is unknown. \tn % Row Count 10 (+ 6) % Row 3 \SetRowColor{white} \{\{noshy\}\}`struct type *y;` & A data structure pointer. \tn % Row Count 12 (+ 2) % Row 4 \SetRowColor{LightBackground} \{\{noshy\}\}`type z{[}{]};` & An array/string name can be used as a pointer to the first array element. \tn % Row Count 16 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Accessing}}} \tn % Row Count 17 (+ 1) % Row 6 \SetRowColor{LightBackground} \{\{noshy\}\}`x` & A memory address. \tn % Row Count 18 (+ 1) % Row 7 \SetRowColor{white} \{\{noshy\}\}`*x` & Value stored at that address. \tn % Row Count 20 (+ 2) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}`y-\textgreater{}a` & Value stored in structure pointer `y` member `a`. \tn % Row Count 23 (+ 3) % Row 9 \SetRowColor{white} \{\{noshy\}\}`\&varName` & Memory address of normal variable `varName`. \tn % Row Count 25 (+ 2) % Row 10 \SetRowColor{LightBackground} \{\{noshy\}\}`*(type *)v` & \{\{noshy\}\}Dereferencing a `void` pointer as a `type` pointer. \tn % Row Count 28 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}A pointer is a variable that holds a memory location.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Arrays}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Declaring}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{noshy\}\}`type name{[}int{]};` & You set array length. \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \{\{noshy\}\}`type name{[}int{]} = \{x, y, z\};` & You set array length and initialise elements. \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} \{\{noshy\}\}`type name{[}int{]} = \{x\};` & You set array length and initialise all elements to `x`. \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{noshy\}\}`type name{[}{]} = \{x, y, z\};` & Compiler sets array length based on initial elements. \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Size cannot be changed after declaration.}}} \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Dimensions}}} \tn % Row Count 15 (+ 1) % Row 7 \SetRowColor{white} \{\{noshy\}\}`name{[}int{]}` & One dimension array. \tn % Row Count 16 (+ 1) % Row 8 \SetRowColor{LightBackground} \{\{noshy\}\}`name{[}int{]}{[}int{]}` & Two dimensional array. \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Accessing}}} \tn % Row Count 19 (+ 1) % Row 10 \SetRowColor{LightBackground} \{\{noshy\}\}`name{[}int{]}` & Value of element `int` in array `name`. \tn % Row Count 21 (+ 2) % Row 11 \SetRowColor{white} \{\{noshy\}\}`*(name + int)` & Same as `name{[}int{]}`. \tn % Row Count 23 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Elements are contiguously numbered ascending from `0`.}}} \tn % Row Count 25 (+ 2) % Row 13 \SetRowColor{white} \{\{noshy\}\}`\&name{[}int{]}` & Memory address of element `int` in array `name`. \tn % Row Count 28 (+ 3) % Row 14 \SetRowColor{LightBackground} \{\{noshy\}\}`name + int` & Same as `\&name{[}int{]}`. \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Arrays (cont)}} \tn % Row 15 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Elements are stored in contiguous memory.}}} \tn % Row Count 2 (+ 2) % Row 16 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Measuring}}} \tn % Row Count 3 (+ 1) % Row 17 \SetRowColor{LightBackground} \{\{noshy\}\}`sizeof(array) / sizeof(arrayType)` & \{\{noshy\}\}Returns length of `array`. {\emph{(Unsafe)}} \tn % Row Count 6 (+ 3) % Row 18 \SetRowColor{white} \{\{noshy\}\}`sizeof(array) / sizeof(array{[}0{]})` & \{\{noshy\}\}Returns length of `array`. {\emph{(Safe)}} \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.8 cm} x{3.2 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Strings}} \tn % Row 0 \SetRowColor{LightBackground} \{\{noshy\}\}`'A'` character & Single quotes. \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{noshy\}\}`"AB"` string & Double quotes. \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`\textbackslash{}0` & Null terminator. \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Strings are }}`char`{\emph{ arrays.}}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{ac\}\}\{\{nobreak\}\}`char name{[}4{]} = "Ash";`} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{is equivalent to}}} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`char name{[}4{]} = \{'A', 's', 'h', '\textbackslash{}0'\};`} \tn % Row Count 8 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{ac\}\}\{\{noshy\}\}`int i; for(i = 0; name{[}i{]}; i++)\{\}`} \tn % Row Count 10 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`\textbackslash{}0` {\emph{evaluates as false.}}} \tn % Row Count 11 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}Strings must include a `char` element for `\textbackslash{}0`.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.296 cm} x{2.952 cm} x{1.224 cm} x{1.728 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{Escape Characters}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}`\textbackslash{}a` & \{\{noshy\}\}alarm (bell/beep) & \{\{nobreak\}\}`\textbackslash{}b` & \{\{noshy\}\}backspace \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \{\{nobreak\}\}`\textbackslash{}f` & \{\{noshy\}\}formfeed & \{\{nobreak\}\}`\textbackslash{}n` & \{\{noshy\}\}newline \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`\textbackslash{}r` & \{\{noshy\}\}carriage return & \{\{nobreak\}\}`\textbackslash{}t` & \{\{noshy\}\}horizontal tab \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`\textbackslash{}v` & \{\{noshy\}\}vertical tab & \{\{nobreak\}\}`\textbackslash{}\textbackslash{} ` & \{\{noshy\}\}backslash \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{nobreak\}\}`\textbackslash{}'` & \{\{noshy\}\}single quote & \{\{nobreak\}\}`\textbackslash{}"` & \{\{noshy\}\}double quote \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} \{\{nobreak\}\}`\textbackslash{}?` & \{\{noshy\}\}question mark & & \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}`\textbackslash{}nnn` & \{\{noshy\}\}Any octal ANSI character code. & & \tn % Row Count 21 (+ 3) % Row 7 \SetRowColor{white} `\textbackslash{}xhh` & \{\{noshy\}\}Any hexadecimal ANSI character code. & & \tn % Row Count 24 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Declaring}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`type/void funcName({[}args...{]})\{ {[}return var;{]} \}`} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Function names follow the same restrictions as variable names but must {\bf{also}} be unique.}}} \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} \{\{noshy\}\}`type/void` & \{\{noshy\}\}Return value type (`void` if none.) \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{noshy\}\}`funcName()` & \{\{noshy\}\}Function name and argument parenthesis. \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} \{\{noshy\}\}`args...` & \{\{noshy\}\}Argument types \& names (`void` if none.) \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} \{\{noshy\}\}`\{\}` & Function content delimiters. \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} \{\{noshy\}\}`return var;` & \{\{noshy\}\}Value to return to function call origin. Skip for `void` type functions. Functions exit immediately after a `return`. \tn % Row Count 24 (+ 7) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{By Value vs By Pointer}}} \tn % Row Count 25 (+ 1) % Row 9 \SetRowColor{white} \{\{noshy\}\}`void f(type x); f(y);` & \{\{noshy\}\}Passing variable `y` to function `f` argument `x` (by value.) \tn % Row Count 29 (+ 4) % Row 10 \SetRowColor{LightBackground} \{\{noshy\}\}`void f(type {\bf{*x}}); f({\bf{array}});` & \{\{noshy\}\}Passing an array/string to function `f` argument `x` (by pointer.) \tn % Row Count 33 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Functions (cont)}} \tn % Row 11 \SetRowColor{LightBackground} \{\{noshy\}\}`void f(type {\bf{*x}}); f({\bf{structure}});` & \{\{noshy\}\}Passing a structure to function `f` argument `x` (by pointer.) \tn % Row Count 4 (+ 4) % Row 12 \SetRowColor{white} \{\{noshy\}\}`void f(type {\bf{*x}}); f({\bf{\&y}});` & \{\{noshy\}\}Passing variable `y` to function `f` argument `x` (by pointer.) \tn % Row Count 8 (+ 4) % Row 13 \SetRowColor{LightBackground} \{\{noshy\}\}`type f()\{ return x; \}` & \{\{noshy\}\}Returning by value. \tn % Row Count 10 (+ 2) % Row 14 \SetRowColor{white} \{\{noshy\}\}`type f()\{ type x; return {\bf{\&x}}; \}` & \{\{noshy\}\}Returning a variable by pointer. \tn % Row Count 13 (+ 3) % Row 15 \SetRowColor{LightBackground} \{\{noshy\}\}`type f()\{ {\bf{static}} type x{[}{]}; return {\bf{\&x}}; \}` & \{\{noshy\}\}Returning an \seqsplit{array/string/structure} by pointer. The `static` qualifier is necessary otherwise `x` won't exist after the function exits. \tn % Row Count 21 (+ 8) % Row 16 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Passing by pointer allows you to change the originating variable within the function.}}} \tn % Row Count 24 (+ 3) % Row 17 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Scope}}} \tn % Row Count 25 (+ 1) % Row 18 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`int f()\{ int i = 0; \} \textasciitilde{}\textasciitilde{}i++;\textasciitilde{}\textasciitilde{}`\{\{fa-times\}\}} \tn % Row Count 27 (+ 2) % Row 19 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{`i` is declared inside `f()`, it doesn't exist outside that function.}}} \tn % Row Count 29 (+ 2) % Row 20 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Prototyping}}} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Functions (cont)}} \tn % Row 21 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`type funcName(args...);`} \tn % Row Count 1 (+ 1) % Row 22 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Place before declaring or referencing respective function (usually before `main`.)}}} \tn % Row Count 3 (+ 2) % Row 23 \SetRowColor{LightBackground} \{\{noshy\}\}`type funcName({[}args...{]})` & \{\{noshy\}\}Same `type`, `name` and `args...` as respective function. \tn % Row Count 7 (+ 4) % Row 24 \SetRowColor{white} \{\{noshy\}\}`;` & \{\{noshy\}\} Semicolon instead of function delimiters. \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{main()}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`int main(int argc, char *argv{[}{]})\{return int;\}`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Anatomy}}} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \{\{noshy\}\}`int main` & Program entry point. \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \{\{noshy\}\}`int argc` & \# of command line arguments. \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \{\{nobreak\}\}`char *argv{[}{]}` & Command line arguments in an array of strings. \#1 is always the program filename. \tn % Row Count 11 (+ 4) % Row 5 \SetRowColor{white} \{\{noshy\}\}`return int;` & Exit status (`integer`) returned to the OS upon program exit. \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Command Line Arguments}}} \tn % Row Count 15 (+ 1) % Row 7 \SetRowColor{white} \{\{nobreak\}\}`app two 3` & Three arguments, `"app"`, `"two"` and `"3"`. \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} \{\{noshy\}\}`app "two 3"` & Two arguments, `"app"` and `"two 3"`. \tn % Row Count 19 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`main` is the first function called when the program executes.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Conditional (Branching)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{if, else if, else}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{noshy\}\}`if(a) b;` & \{\{noshy\}\}Evaluates `b` if `a` is true. \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \{\{noshy\}\}`if(a)\{ b; c; \}` & \{\{noshy\}\}Evaluates `b` and `c` if `a` is true. \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} \{\{noshy\}\}`if(a)\{ b; \}else\{ c; \}` & \{\{noshy\}\}Evaluates `b` if `a` is true, `c` otherwise. \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{noshy\}\}`if(a)\{ b; \}else if(c)\{ d; \}else\{ e; \}` & \{\{noshy\}\}Evaluates `b` if `a` is true, otherwise `d` if `c` is true, otherwise `e`. \tn % Row Count 14 (+ 5) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{switch, case, break}}} \tn % Row Count 15 (+ 1) % Row 6 \SetRowColor{LightBackground} \{\{noshy\}\}`{\bf{switch}}(a)\{ {\bf{case}} b{\bf{:}} c; \}` & \{\{noshy\}\}Evaluates `c` if `a` equals `b`. \tn % Row Count 18 (+ 3) % Row 7 \SetRowColor{white} \{\{noshy\}\}`switch(a)\{ {\bf{default:}} b; \}` & \{\{noshy\}\}Evaluates `b` if `a` matches no other case. \tn % Row Count 21 (+ 3) % Row 8 \SetRowColor{LightBackground} \{\{noshy\}\}`switch(a)\{ {\bf{case}} b{\bf{:}} {\bf{case}} c{\bf{:}} d; \}` & \{\{noshy\}\}Evaluates `d` if `a` equals either `b` or `c`. \tn % Row Count 24 (+ 3) % Row 9 \SetRowColor{white} \{\{noshy\}\}`switch(a)\{ {\bf{case}} b{\bf{:}} c; {\bf{case}} d{\bf{:}} e; default: f; \}` & \{\{noshy\}\}Evaluates `c`, `e` and `f` if `a` equals `b`, `e` and `f` if `a` equals `d`, otherwise `f`. \tn % Row Count 29 (+ 5) % Row 10 \SetRowColor{LightBackground} \{\{noshy\}\}`switch(a)\{ case b: c; {\bf{break;}} case d: e; {\bf{break;}} default: f; \}` & \{\{noshy\}\}Evaluates `c` if `a` equals `b`, `e` if `a` equals `d` and `e` otherwise. \tn % Row Count 34 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Iterative (Looping)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{while}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`int x = 0; {\bf{while(x \textless{} 10)\{}} x += 2; {\bf{\}}}`} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Loop skipped if test condition initially false.}}} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \{\{noshy\}\}`int x = 0;` & \{\{noshy\}\}Declare and initialise integer `x`. \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \{\{noshy\}\}`while()` & \{\{noshy\}\}Loop keyword and condition parenthesis. \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \{\{noshy\}\}`x \textless{} 10` & \{\{noshy\}\}Test condition. \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} \{\{noshy\}\}`\{\}` & \{\{noshy\}\}Loop delimiters. \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} \{\{noshy\}\}`x += 2;` & \{\{noshy\}\}Loop contents. \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{do while}}} \tn % Row Count 16 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`char c = 'A'; {\bf{do \{}} c++; {\bf{\} while(c != 'Z');}}`} \tn % Row Count 18 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Always runs through loop at least once.}}} \tn % Row Count 20 (+ 2) % Row 11 \SetRowColor{white} \{\{noshy\}\}`char c = 'A';` & \{\{noshy\}\}Declare and initialise character `c`. \tn % Row Count 22 (+ 2) % Row 12 \SetRowColor{LightBackground} \{\{noshy\}\}`do` & \{\{noshy\}\}Loop keyword. \tn % Row Count 23 (+ 1) % Row 13 \SetRowColor{white} \{\{noshy\}\}`\{\}` & \{\{noshy\}\}Loop delimiters. \tn % Row Count 25 (+ 2) % Row 14 \SetRowColor{LightBackground} \{\{noshy\}\}`c++;` & \{\{noshy\}\}Loop contents. \tn % Row Count 26 (+ 1) % Row 15 \SetRowColor{white} \{\{noshy\}\}`while();` & \{\{noshy\}\}Loop keyword and condition parenthesis. {\emph{Note semicolon.}} \tn % Row Count 29 (+ 3) % Row 16 \SetRowColor{LightBackground} \{\{noshy\}\}`c != 'Z'` & \{\{noshy\}\}Test condition. \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Iterative (Looping) (cont)}} \tn % Row 17 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{for}}} \tn % Row Count 1 (+ 1) % Row 18 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`int i; {\bf{for(i = 0; n{[}i{]} != '\textbackslash{}0'; i++)\{\}}}` (C89)} \tn % Row Count 3 (+ 2) % Row 19 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}OR} \tn % Row Count 4 (+ 1) % Row 20 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`{\bf{for}}(int {\bf{i = 0; n{[}i{]} != '\textbackslash{}0'; i++)\{\}}}` (C99+)} \tn % Row Count 6 (+ 2) % Row 21 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Compact increment/decrement based loop.}}} \tn % Row Count 8 (+ 2) % Row 22 \SetRowColor{white} \{\{noshy\}\}`int i;` & Declares integer `i`. \tn % Row Count 10 (+ 2) % Row 23 \SetRowColor{LightBackground} \{\{noshy\}\}`for()` & \{\{noshy\}\}Loop keyword. \tn % Row Count 12 (+ 2) % Row 24 \SetRowColor{white} \{\{noshy\}\}`i = 0;` & \{\{noshy\}\}Initialises integer `i`. {\emph{Semicolon.}} \tn % Row Count 14 (+ 2) % Row 25 \SetRowColor{LightBackground} \{\{noshy\}\}`n{[}i{]} != '\textbackslash{}0';` & \{\{noshy\}\}Test condition. {\emph{Semicolon.}} \tn % Row Count 16 (+ 2) % Row 26 \SetRowColor{white} \{\{noshy\}\}`i++` & \{\{noshy\}\}Increments `i`. {\emph{No semicolon.}} \tn % Row Count 18 (+ 2) % Row 27 \SetRowColor{LightBackground} \{\{noshy\}\}`\{\}` & \{\{noshy\}\}Loop delimiters. \tn % Row Count 20 (+ 2) % Row 28 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{continue}}} \tn % Row Count 21 (+ 1) % Row 29 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`int i=0; while(i\textless{}10)\{ i++; {\bf{continue;}} i-{}-;\}`} \tn % Row Count 23 (+ 2) % Row 30 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Skips rest of loop contents and restarts at the beginning of the loop.}}} \tn % Row Count 25 (+ 2) % Row 31 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{break}}} \tn % Row Count 26 (+ 1) % Row 32 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`int i=0; while(1)\{ if(x==10)\{{\bf{break}};\} i++; \}`} \tn % Row Count 28 (+ 2) % Row 33 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Skips rest of loop contents and exits loop.}}} \tn % Row Count 30 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Console Input/Output}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{nobreak\}\}`\#include \textless{}stdio.h\textgreater{}`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Characters}}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`getchar()` & \{\{noshy\}\}Returns a single character's ANSI code from the input stream buffer as an {\emph{integer}}. {\emph{(safe)}} \tn % Row Count 8 (+ 6) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`putchar(int)` & \{\{noshy\}\}Prints a single character from an ANSI code {\emph{integer}} to the output stream buffer. \tn % Row Count 13 (+ 5) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Strings}}} \tn % Row Count 14 (+ 1) % Row 5 \SetRowColor{white} \{\{nobreak\}\}`gets(strName)` & \{\{noshy\}\}Reads a line from the input stream into a string variable. {\emph{(Unsafe, removed in C11.)}} \tn % Row Count 19 (+ 5) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{noshy\}\}Alternative} \tn % Row Count 20 (+ 1) % Row 7 \SetRowColor{white} \{\{noshy\}\}`fgets(strName, length, stdin);` & \{\{noshy\}\}Reads a line from the input stream into a string variable. {\emph{(Safe)}} \tn % Row Count 24 (+ 4) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}`puts("string")` & \{\{noshy\}\}Prints a string to the output stream. \tn % Row Count 27 (+ 3) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Formatted Data}}} \tn % Row Count 28 (+ 1) % Row 10 \SetRowColor{LightBackground} \{\{nobreak\}\}`scanf("\%d", \&x)` & \{\{noshy\}\}Read value/s (type defined by format string) into variable/s (type must match) from the input stream. Stops reading at the first whitespace. {\emph{`\&` prefix not required for arrays (including strings.)}} {\emph{(unsafe)}} \tn % Row Count 39 (+ 11) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Console Input/Output (cont)}} \tn % Row 11 \SetRowColor{LightBackground} `printf("I love \%c \%d!", 'C', 99)` & \{\{noshy\}\}Prints data (formats defined by the format string) as a string to the output stream. \tn % Row Count 5 (+ 5) % Row 12 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{noshy\}\}Alternative} \tn % Row Count 6 (+ 1) % Row 13 \SetRowColor{LightBackground} \{\{noshy\}\}`fgets(strName, length, stdin); sscanf(strName, "\%d", \&x);` & Uses `fgets` to limit the input length, then uses `sscanf` to read the resulting string in place of `scanf`. {\emph{(safe)}} \tn % Row Count 12 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}The stream buffers must be flushed to reflect changes. String terminator characters can flush the output while newline characters can flush the input. \newline \newline {\emph{Safe}} functions are those that let you specify the length of the input. {\emph{Unsafe}} functions do not, and carry the risk of memory overflow.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{File Input/Output}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`\#include \textless{}stdio.h\textgreater{}`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Opening}}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`FILE *fptr = fopen(filename, mode);`} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \{\{noshy\}\}`FILE *fptr` & \{\{noshy\}\}Declares `fptr` as a FILE type pointer (stores stream location instead of memory location.) \tn % Row Count 9 (+ 5) % Row 4 \SetRowColor{LightBackground} \{\{noshy\}\}`fopen()` & \{\{noshy\}\}Returns a stream location pointer if successful, `0` otherwise. \tn % Row Count 13 (+ 4) % Row 5 \SetRowColor{white} \{\{noshy\}\}`filename` & \{\{noshy\}\}String containing file's directory path \& name. \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} \{\{noshy\}\}`mode` & \{\{noshy\}\}String specifying the file access mode. \tn % Row Count 19 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Modes} \tn % Row Count 20 (+ 1) % Row 8 \SetRowColor{LightBackground} \{\{noshy\}\}`"r"` / `"rb"` & \{\{noshy\}\}Read existing text/binary file. \tn % Row Count 22 (+ 2) % Row 9 \SetRowColor{white} \{\{noshy\}\}`"w"` / `"wb"` & \{\{noshy\}\}Write new/over existing text/binary file. \tn % Row Count 25 (+ 3) % Row 10 \SetRowColor{LightBackground} \{\{noshy\}\}`"a"` / `"ab"` & \{\{noshy\}\}Write new/append to existing text/binary file. \tn % Row Count 28 (+ 3) % Row 11 \SetRowColor{white} \{\{noshy\}\}`"r+"` / `"r+b"` / `"rb+"` & \{\{noshy\}\}Read and write existing text/binary file. \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{File Input/Output (cont)}} \tn % Row 12 \SetRowColor{LightBackground} \{\{noshy\}\}`"w+"` / `"w+b"` / `"wb+"` & \{\{noshy\}\}Read and write new/over existing text/binary file. \tn % Row Count 3 (+ 3) % Row 13 \SetRowColor{white} \{\{noshy\}\}`"a+"` / `"a+b"` / `"ab+"` & \{\{noshy\}\}Read and write new/append to existing text/binary file. \tn % Row Count 7 (+ 4) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Closing}}} \tn % Row Count 8 (+ 1) % Row 15 \SetRowColor{white} \{\{noshy\}\}`fclose(fptr);` & \{\{noshy\}\}Flushes buffers and closes stream. Returns `0` if successful, `EOF` otherwise. \tn % Row Count 13 (+ 5) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Random Access}}} \tn % Row Count 14 (+ 1) % Row 17 \SetRowColor{white} \{\{noshy\}\}`ftell(fptr)` & \{\{noshy\}\}Return current file position as a long integer. \tn % Row Count 17 (+ 3) % Row 18 \SetRowColor{LightBackground} \{\{noshy\}\}`fseek(fptr, offset, origin);` & \{\{noshy\}\}Sets current file position. Returns {\emph{false}} is successful, {\emph{true}} otherwise. The `offset` is a long integer type. \tn % Row Count 24 (+ 7) % Row 19 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{noshy\}\}Origins} \tn % Row Count 25 (+ 1) % Row 20 \SetRowColor{LightBackground} `SEEK\_SET` & \{\{noshy\}\}Beginning of file. \tn % Row Count 27 (+ 2) % Row 21 \SetRowColor{white} `SEEK\_CUR` & \{\{noshy\}\}Current position in file. \tn % Row Count 29 (+ 2) % Row 22 \SetRowColor{LightBackground} `SEEK\_END` & \{\{noshy\}\}End of file. \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{File Input/Output (cont)}} \tn % Row 23 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Utilities}}} \tn % Row Count 1 (+ 1) % Row 24 \SetRowColor{white} \{\{noshy\}\}`feof(fptr)` & \{\{noshy\}\}Tests end-of-file indicator. \tn % Row Count 3 (+ 2) % Row 25 \SetRowColor{LightBackground} \{\{noshy\}\}`rename(strOldName, strNewName)` & \{\{noshy\}\}Renames a file. \tn % Row Count 6 (+ 3) % Row 26 \SetRowColor{white} \{\{noshy\}\}`remove(strName)` & \{\{noshy\}\}Deletes a file. \tn % Row Count 8 (+ 2) % Row 27 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Characters}}} \tn % Row Count 9 (+ 1) % Row 28 \SetRowColor{white} \{\{noshy\}\}`fgetc(fptr)` & Returns character read or EOF if unsuccessful. {\emph{(safe)}} \tn % Row Count 12 (+ 3) % Row 29 \SetRowColor{LightBackground} \{\{noshy\}\}`fputc(int c, fptr)` & Returns character written or EOF if unsuccessful. \tn % Row Count 15 (+ 3) % Row 30 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Strings}}} \tn % Row Count 16 (+ 1) % Row 31 \SetRowColor{LightBackground} \{\{noshy\}\}`fgets(char *s, int n, fptr)` & Reads `n-1` characters from file `fptr` into string `s`. Stops at `EOF` and `\textbackslash{}n`. {\emph{(safe)}} \tn % Row Count 21 (+ 5) % Row 32 \SetRowColor{white} \{\{noshy\}\}`fputs(char *s, fptr)` & Writes string `s` to file `fptr`. Returns non-negative on success, `EOF` otherwise. \tn % Row Count 26 (+ 5) % Row 33 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Formatted Data}}} \tn % Row Count 27 (+ 1) % Row 34 \SetRowColor{white} \{\{noshy\}\}`fscanf(fptr, format, {[}...{]})` & Same as `scanf` with additional file pointer parameter. {\emph{(unsafe)}} \tn % Row Count 31 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{File Input/Output (cont)}} \tn % Row 35 \SetRowColor{LightBackground} \{\{noshy\}\}`fprintf(fptr, format, {[}...{]})` & Same as `printf` with additional file pointer parameter. \tn % Row Count 3 (+ 3) % Row 36 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{noshy\}\}Alternative} \tn % Row Count 4 (+ 1) % Row 37 \SetRowColor{LightBackground} \{\{noshy\}\}`fgets(strName, length, fptr); sscanf(strName, "\%d", \&x);` & Uses `fgets` to limit the input length, then uses `sscanf` to read the resulting string in place of `scanf`. {\emph{(safe)}} \tn % Row Count 10 (+ 6) % Row 38 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Binary}}} \tn % Row Count 11 (+ 1) % Row 39 \SetRowColor{LightBackground} \{\{noshy\}\}`fread(void *ptr, sizeof(element), number, fptr)` & Reads a `number` of `element`s from `fptr` to array `*ptr`. {\emph{(safe)}} \tn % Row Count 15 (+ 4) % Row 40 \SetRowColor{white} \{\{noshy\}\}`fwrite(void *ptr, sizeof(element), number, fptr)` & Writes a `number` of `element`s to file `fptr` from array `*ptr`. \tn % Row Count 19 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Safe}} functions are those that let you specify the length of the input. {\emph{Unsafe}} functions do not, and carry the risk of memory overflow.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.672 cm} x{2.964 cm} x{2.964 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Placeholder Types (f/printf And f/scanf)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`printf("\%d\%d...", arg1, arg2...);`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{bt\}\}{\bf{Type}} & \{\{ac\}\}\{\{bt\}\}{\bf{Example}} & \{\{bt\}\}{\bf{Description}} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`\%d` or `\%i` & \{\{ac\}\}\{\{noshy\}\}`-42` & \{\{noshy\}\}Signed decimal integer. \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`\%u` & \{\{ac\}\}\{\{noshy\}\}`42` & \{\{noshy\}\}Unsigned decimal integer. \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{nobreak\}\}`\%o` & \{\{ac\}\}\{\{noshy\}\}`52` & \{\{noshy\}\}Unsigned octal integer. \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} \{\{nobreak\}\}`\%x` or `\%X` & \{\{ac\}\}\{\{noshy\}\}`2a or 2A` & \{\{noshy\}\}Unsigned hexadecimal integer. \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}`\%f` or `\%F` & \{\{ac\}\}\{\{noshy\}\}`1.21` & \{\{noshy\}\}Signed decimal float. \tn % Row Count 18 (+ 3) % Row 7 \SetRowColor{white} \{\{nobreak\}\}`\%e` or `\%E` & \{\{ac\}\}\{\{noshy\}\}`1.21e+9` or `1.21E+9` & \{\{noshy\}\}Signed decimal w/ scientific notation. \tn % Row Count 22 (+ 4) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}`\%g` or `\%G` & \{\{ac\}\}\{\{noshy\}\}`1.21e+9` or `1.21E+9` & \{\{noshy\}\}Shortest representation of `\%f`/`\%F` or `\%e`/`\%E`. \tn % Row Count 26 (+ 4) % Row 9 \SetRowColor{white} \{\{nobreak\}\}`\%a` or `\%A` & \{\{ac\}\}\{\{noshy\}\}`0x1.207c8ap+30` or \seqsplit{`0X1.207C8AP+30`} & \{\{noshy\}\}Signed hexadecimal float. \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{1.672 cm} x{2.964 cm} x{2.964 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Placeholder Types (f/printf And f/scanf) (cont)}} \tn % Row 10 \SetRowColor{LightBackground} `\%c` & \{\{ac\}\}\{\{noshy\}\}`a` & \{\{noshy\}\}A character. \tn % Row Count 2 (+ 2) % Row 11 \SetRowColor{white} `\%s` & \{\{ac\}\}\{\{noshy\}\}`A String.` & \{\{noshy\}\}A character string. \tn % Row Count 4 (+ 2) % Row 12 \SetRowColor{LightBackground} `\%p` & \{\{ac\}\}\{\{noshy\}\}~ & \{\{noshy\}\}A pointer. \tn % Row Count 6 (+ 2) % Row 13 \SetRowColor{white} `\%\%` & \{\{ac\}\}\{\{noshy\}\}`\%` & \{\{noshy\}\}A percent character. \tn % Row Count 8 (+ 2) % Row 14 \SetRowColor{LightBackground} `\%n` & \{\{noshy\}\}No output, saves \# of characters printed so far. Respective printf argument must be an integer pointer. & \tn % Row Count 16 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}The pointer format is architecture and implementation dependant.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Placeholder Formatting (f/printf And f/scanf)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`\%{[}Flags{]}{[}Width{]}{[}.Precision{]}{[}Length{]}Type`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Flags}}} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`-` & \{\{noshy\}\}Left justify instead of default right justify. \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`+` & \{\{noshy\}\}Sign for both positive numbers and negative. \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{nobreak\}\}`\#` & \{\{noshy\}\}Precede with `0`, `0x` or `0X` for `\%o`, `\%x` and `\%X` tokens. \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} \{\{nobreak\}\}`space` & \{\{noshy\}\}Left pad with spaces. \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}`0` & \{\{noshy\}\}Left pad with zeroes. \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Width}}} \tn % Row Count 17 (+ 1) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}`integer` & \{\{noshy\}\}Minimum number of characters to print: invokes padding if necessary. Will not truncate. \tn % Row Count 21 (+ 4) % Row 9 \SetRowColor{white} \{\{nobreak\}\}`*` & \{\{noshy\}\}Width specified by a preceding argument in `printf`. \tn % Row Count 24 (+ 3) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Precision}}} \tn % Row Count 25 (+ 1) % Row 11 \SetRowColor{white} \{\{nobreak\}\}`.integer` & \{\{noshy\}\}Minimum \# of digits to print for `\%d`, `\%i`, `\%o`, `\%u`, `\%x`, `\%X`. Left pads with zeroes. Will not truncate. Skips values of 0. \tn % Row Count 31 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Placeholder Formatting (f/printf And f/scanf) (cont)}} \tn % Row 12 \SetRowColor{LightBackground} \{\{nobreak\}\}~ & \{\{noshy\}\}Minimum \# of digits to print after decimal point for `\%a`, `\%A`, `\%e`, `\%E`, `\%f`, `\%F` (default of 6.) \tn % Row Count 5 (+ 5) % Row 13 \SetRowColor{white} \{\{nobreak\}\}~ & \{\{noshy\}\}Minimum \# of significant digits to print for `\%g` \& `\%G`. \tn % Row Count 8 (+ 3) % Row 14 \SetRowColor{LightBackground} \{\{nobreak\}\}~ & \{\{noshy\}\}Maximum \# of characters to print from `\%s` (a string.) \tn % Row Count 11 (+ 3) % Row 15 \SetRowColor{white} \{\{nobreak\}\}`.` & \{\{noshy\}\}If no `integer` is given, default of 0. \tn % Row Count 13 (+ 2) % Row 16 \SetRowColor{LightBackground} \{\{nobreak\}\}`.*` & \{\{noshy\}\}Precision specified by a preceding argument in `printf`. \tn % Row Count 16 (+ 3) % Row 17 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Length}}} \tn % Row Count 17 (+ 1) % Row 18 \SetRowColor{LightBackground} \{\{nobreak\}\}`hh` & \{\{noshy\}\}Display a `char` as `int`. \tn % Row Count 19 (+ 2) % Row 19 \SetRowColor{white} \{\{nobreak\}\}`h` & \{\{noshy\}\}Display a `short` as `int`. \tn % Row Count 21 (+ 2) % Row 20 \SetRowColor{LightBackground} \{\{nobreak\}\}`l` & \{\{noshy\}\}Display a `long` integer. \tn % Row Count 23 (+ 2) % Row 21 \SetRowColor{white} \{\{nobreak\}\}`ll` & \{\{noshy\}\}Display a `long long` integer. \tn % Row Count 25 (+ 2) % Row 22 \SetRowColor{LightBackground} \{\{nobreak\}\}`L` & \{\{noshy\}\}Display a `long double` float. \tn % Row Count 27 (+ 2) % Row 23 \SetRowColor{white} \{\{nobreak\}\}`z` & \{\{noshy\}\}Display a `size\_t` integer. \tn % Row Count 29 (+ 2) % Row 24 \SetRowColor{LightBackground} \{\{nobreak\}\}`j` & \{\{noshy\}\}Display a `intmax\_t` integer. \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Placeholder Formatting (f/printf And f/scanf) (cont)}} \tn % Row 25 \SetRowColor{LightBackground} \{\{nobreak\}\}`t` & \{\{noshy\}\}Display a `ptrdiff\_t` integer. \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Preprocessor Directives}} \tn % Row 0 \SetRowColor{LightBackground} \{\{noshy\}\}`\#include \textless{}{\bf{inbuilt}}.h\textgreater{}` & \{\{noshy\}\}Replaces line with contents of a standard C header file. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \{\{noshy\}\}`\#include "./{\bf{custom}}.h"` & \{\{noshy\}\}Replaces line with contents of a custom header file. {\emph{Note dir path prefix \& quotations.}} \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} \{\{noshy\}\}`\#define NAME value` & \{\{noshy\}\}Replaces all occurrences of `NAME` with `value`. \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Comments}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{// We're single-line comments! \newline // Nothing compiled after // on these lines. \newline \newline /* I'm a multi-line comment! \newline Nothing compiled between \newline these delimiters. */} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.232 cm} x{1.656 cm} x{1.656 cm} x{1.656 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{C Reserved Keywords}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}`\_Alignas` & \{\{nobreak\}\}`break` & \{\{nobreak\}\}`float` & \{\{nobreak\}\}`signed` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \{\{nobreak\}\}`\_Alignof` & \{\{nobreak\}\}`case` & \{\{nobreak\}\}`for` & \{\{nobreak\}\}`sizeof` \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`\_Atomic` & \{\{nobreak\}\}`char` & \{\{nobreak\}\}`goto` & \{\{nobreak\}\}`static` \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`\_Bool` & \{\{nobreak\}\}`const` & \{\{nobreak\}\}`if` & \{\{nobreak\}\}`struct` \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{nobreak\}\}`\_Complex` & \{\{nobreak\}\}`continue` & \{\{nobreak\}\}`inline` & \{\{nobreak\}\}`switch` \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} \{\{nobreak\}\}`\_Generic` & \{\{nobreak\}\}`default` & \{\{nobreak\}\}`int` & \{\{nobreak\}\}`typedef` \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}`\_Imaginary` & \{\{nobreak\}\}`do` & \{\{nobreak\}\}`long` & \{\{nobreak\}\}`union` \tn % Row Count 20 (+ 2) % Row 7 \SetRowColor{white} \{\{nobreak\}\}`\_Noreturn` & \{\{nobreak\}\}`double` & \{\{nobreak\}\}`register` & \{\{nobreak\}\}`unsigned` \tn % Row Count 23 (+ 3) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}`\_Static\_assert` & \{\{nobreak\}\}`else` & \{\{nobreak\}\}`restrict` & \{\{nobreak\}\}`void` \tn % Row Count 26 (+ 3) % Row 9 \SetRowColor{white} \{\{nobreak\}\}`\_Thread\_local` & \{\{nobreak\}\}`enum` & \{\{nobreak\}\}`return` & \{\{nobreak\}\}`volatile` \tn % Row Count 29 (+ 3) % Row 10 \SetRowColor{LightBackground} \{\{nobreak\}\}`auto` & \{\{nobreak\}\}`extern` & \{\{nobreak\}\}`short` & \{\{nobreak\}\}`while` \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.232 cm} x{1.656 cm} x{1.656 cm} x{1.656 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{C Reserved Keywords (cont)}} \tn % Row 11 \SetRowColor{LightBackground} \{\{nobreak\}\}`\_A-Z...` & \{\{nobreak\}\}`\_\_...` & & \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.8 cm} x{1.8 cm} x{1.8 cm} x{1.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{C / POSIX Reserved Keywords}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}`E{[}0-9{]}...` & \{\{nobreak\}\}`E{[}A-Z{]}...` & \{\{nobreak\}\}`is{[}a-z{]}...` & \{\{nobreak\}\}`to{[}a-z{]}...` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \{\{nobreak\}\}`LC\_{[}A-Z{]}...` & \{\{nobreak\}\}`SIG{[}A-Z{]}...` & \{\{nobreak\}\}`SIG\_{[}A-Z{]}...` & \{\{nobreak\}\}`str{[}a-z{]}...` \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`mem{[}a-z{]}...` & \{\{nobreak\}\}`wcs{[}a-z{]}...` & \{\{nobreak\}\}`...\_t` & \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{4}{x{8.4cm}}{\{\{bt\}\}\{\{ac\}\}\{\{link="http://www.gnu.org/software/libc/manual/html\_node/Reserved-Names.html"\}\}GNU Reserved Names\{\{/link\}\}} \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.84 cm} x{4.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Header Reserved Keywords}} \tn % Row 0 \SetRowColor{LightBackground} {\emph{Name}} & {\emph{Reserved By Library}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \{\{noshy\}\}`d\_...` & \{\{noshy\}\}`dirent.h` \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \{\{noshy\}\}`l\_...` & \{\{noshy\}\}`fcntl.h` \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \{\{noshy\}\}`F\_...` & \{\{noshy\}\}`fcntl.h` \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \{\{noshy\}\}`O\_...` & \{\{noshy\}\}`fcntl.h` \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \{\{noshy\}\}`S\_...` & \{\{noshy\}\}`fcntl.h` \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \{\{noshy\}\}`gr\_...` & \{\{noshy\}\}`grp.h` \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \{\{noshy\}\}`...\_MAX` & \{\{noshy\}\}`limits.h` \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} \{\{noshy\}\}`pw\_...` & \{\{noshy\}\}`pwd.h` \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} \{\{noshy\}\}`sa\_...` & \{\{noshy\}\}`signal.h` \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} \{\{noshy\}\}`SA\_...` & \{\{noshy\}\}`signal.h` \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} \{\{noshy\}\}`st\_...` & \{\{noshy\}\}`sys/stat.h` \tn % Row Count 14 (+ 2) % Row 12 \SetRowColor{LightBackground} \{\{noshy\}\}`S\_...` & \{\{noshy\}\}`sys/stat.h` \tn % Row Count 16 (+ 2) % Row 13 \SetRowColor{white} \{\{noshy\}\}`tms\_...` & \{\{noshy\}\}`sys/times.h` \tn % Row Count 18 (+ 2) % Row 14 \SetRowColor{LightBackground} \{\{noshy\}\}`c\_...` & \{\{noshy\}\}`termios.h` \tn % Row Count 19 (+ 1) % Row 15 \SetRowColor{white} \{\{noshy\}\}`V...` & \{\{noshy\}\}`termios.h` \tn % Row Count 20 (+ 1) % Row 16 \SetRowColor{LightBackground} \{\{noshy\}\}`I...` & \{\{noshy\}\}`termios.h` \tn % Row Count 21 (+ 1) % Row 17 \SetRowColor{white} \{\{noshy\}\}`O...` & \{\{noshy\}\}`termios.h` \tn % Row Count 22 (+ 1) % Row 18 \SetRowColor{LightBackground} \{\{noshy\}\}`TC...` & \{\{noshy\}\}`termios.h` \tn % Row Count 23 (+ 1) % Row 19 \SetRowColor{white} \{\{noshy\}\}`B{[}0-9{]}...` & \{\{noshy\}\}`termios.h` \tn % Row Count 25 (+ 2) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{ac\}\}\{\{link="http://www.gnu.org/software/libc/manual/html\_node/Reserved-Names.html"\}\}GNU Reserved Names\{\{/link\}\}} \tn % Row Count 28 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Heap Space}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`\#include \textless{}stdlib.h\textgreater{}`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Allocating}}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \{\{noshy\}\}`malloc();` & Returns a memory location if successful, `NULL` otherwise. \tn % Row Count 5 (+ 3) % Row 3 \SetRowColor{white} \{\{noshy\}\}`type *x; x = \seqsplit{malloc(sizeof(type));`} & \{\{noshy\}\}Memory for a variable. \tn % Row Count 8 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{noshy\}\}`type *y; y = malloc(sizeof(type) * length );` & \{\{noshy\}\}Memory for an array/string. \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} \{\{noshy\}\}`struct type *z; z = \seqsplit{malloc(sizeof(struct} type));` & \{\{noshy\}\}Memory for a structure. \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Deallocating}}} \tn % Row Count 15 (+ 1) % Row 7 \SetRowColor{white} \{\{noshy\}\}`free(ptrName);` & Removes the memory allocated to `ptrName`. \tn % Row Count 18 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Reallocating}}} \tn % Row Count 19 (+ 1) % Row 9 \SetRowColor{white} \{\{noshy\}\}`realloc(ptrName, size);` & Attempts to resize the memory block assigned to `ptrName`. \tn % Row Count 22 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}The memory addresses you see are from virtual memory the operating system assigns to the program; they are not physical addresses. \newline \newline Referencing memory that isn't assigned to the program will produce an OS segmentation fault.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{The Standard Library}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{nobreak\}\}`\#include \textless{}stdlib.h\textgreater{}`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Randomicity}}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`rand()` & \{\{noshy\}\}Returns a (predictable) random integer between 0 and RAND\_MAX based on the randomiser seed. \tn % Row Count 7 (+ 5) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`RAND\_MAX` & \{\{noshy\}\}The maximum value `rand()` can generate. \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{noshy\}\}`srand(unsigned integer);` & \{\{noshy\}\}Seeds the randomiser with a positive integer. \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} \{\{noshy\}\}`(unsigned) time(NULL)` & \{\{noshy\}\}Returns the computer's tick-tock value. Updates every second. \tn % Row Count 17 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}\{\{noshy\}\}{\bf{Sorting}}} \tn % Row Count 18 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`qsort(array, length, sizeof(type), compFunc);`} \tn % Row Count 20 (+ 2) % Row 8 \SetRowColor{LightBackground} \{\{noshy\}\}`qsort()` & \{\{noshy\}\}Sort using the QuickSort algorithm. \tn % Row Count 23 (+ 3) % Row 9 \SetRowColor{white} \{\{noshy\}\}`array` & \{\{noshy\}\}Array/string name. \tn % Row Count 25 (+ 2) % Row 10 \SetRowColor{LightBackground} \{\{noshy\}\}`length` & \{\{noshy\}\}Length of the array/string. \tn % Row Count 27 (+ 2) % Row 11 \SetRowColor{white} \{\{noshy\}\}`sizeof(type)` & \{\{noshy\}\}Byte size of each element. \tn % Row Count 29 (+ 2) % Row 12 \SetRowColor{LightBackground} \{\{noshy\}\}`compFunc` & \{\{noshy\}\}Comparison function name. \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{The Standard Library (cont)}} \tn % Row 13 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\emph{compFunc}}} \tn % Row Count 1 (+ 1) % Row 14 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`int compFunc( const void *a, const void b* )\{ return( *(int *)a - *(int *)b); \}`} \tn % Row Count 4 (+ 3) % Row 15 \SetRowColor{LightBackground} \{\{noshy\}\}`int compFunc()` & \{\{noshy\}\}Function name unimportant but must return an integer. \tn % Row Count 8 (+ 4) % Row 16 \SetRowColor{white} \{\{noshy\}\}`const void *a, const void *b` & \{\{noshy\}\}Argument names unimportant but must identical otherwise. \tn % Row Count 12 (+ 4) % Row 17 \SetRowColor{LightBackground} \{\{noshy\}\}`return( *(int *)a - *(int *)b);` & Negative result swaps `b` for `a`, positive result swaps `a` for `b`, a result of `0` doesn't swap. \tn % Row Count 17 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}C's inbuilt randomiser is cryptographically insecure: DO NOT use it for security applications.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{The Character Type Library}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`\#include \textless{}ctype.h\textgreater{}`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{bt\}\}\{\{nobreak\}\}`tolower(char)` & \{\{bt\}\}Lowercase `char`. \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`toupper(char)` & Uppercase `char`. \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`isalpha(char)` & True if `char` is a letter of the alphabet, false otherwise. \tn % Row Count 8 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{nobreak\}\}`islower(char)` & True if `char` is a lowercase letter of the alphabet, false otherwise. \tn % Row Count 12 (+ 4) % Row 5 \SetRowColor{white} \{\{nobreak\}\}`isupper(char)` & True if `char` is an uppercase letter of the alphabet, false otherwise. \tn % Row Count 16 (+ 4) % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}`isnumber(char)` & True if `char` is numerical (`0` to `9`) and false otherwise. \tn % Row Count 19 (+ 3) % Row 7 \SetRowColor{white} \{\{nobreak\}\}`isblank` & True if `char` is a whitespace character (`' ', '\textbackslash{}t', '\textbackslash{}n'`) and false otherwise. \tn % Row Count 23 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{The String Library}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`\#include \textless{}string.h\textgreater{}`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{bt\}\}\{\{nobreak\}\}`strlen(a)` & \{\{bt\}\}Returns \# of `char` in string `a` as an integer. Excludes `\textbackslash{}0`. {\emph{(unsafe)}} \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`strcpy(a, b)` & Copies strings. Copies string `b` over string `a` up to and including `\textbackslash{}0`. {\emph{(unsafe)}} \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`strcat(a, b)` & Concatenates strings. Copies string `b` over string `a` up to and including `\textbackslash{}0`, starting at the position of `\textbackslash{}0` in string `a`. {\emph{(unsafe)}} \tn % Row Count 16 (+ 7) % Row 4 \SetRowColor{LightBackground} \{\{nobreak\}\}`strcmp(a, b)` & Compares strings. Returns {\emph{false}} if string `a` equals string `b`, {\emph{true}} otherwise. Ignores characters after `\textbackslash{}0`. {\emph{(unsafe)}} \tn % Row Count 22 (+ 6) % Row 5 \SetRowColor{white} \{\{nobreak\}\}`strstr(a, b)` & Searches for string `b` inside string `a`. Returns a pointer if successful, `NULL` otherwise. {\emph{(unsafe)}} \tn % Row Count 27 (+ 5) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{noshy\}\}Alternatives} \tn % Row Count 28 (+ 1) % Row 7 \SetRowColor{white} \{\{nobreak\}\}`strncpy(a, b, n)` & Copies strings. Copies `n` characters from string `b` over string `a` up to and including `\textbackslash{}0`. {\emph{(safe)}} \tn % Row Count 33 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{The String Library (cont)}} \tn % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}`strncat(a, b, n)` & Concatenates strings. Copies `n` characters from string `b` over string `a` up to and including `\textbackslash{}0`, starting at the position of `\textbackslash{}0` in string `a`. {\emph{(safe)}} \tn % Row Count 7 (+ 7) % Row 9 \SetRowColor{white} \{\{nobreak\}\}`strncmp(a, b, n)` & Compares first `n` characters of two strings. Returns {\emph{false}} if string `a` equals string `b`, {\emph{true}} otherwise. Ignores characters after `\textbackslash{}0`. {\emph{(safe)}} \tn % Row Count 14 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}{\emph{Safe}} functions are those that let you specify the length of the input. {\emph{Unsafe}} functions do not, and carry the risk of memory overflow.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{The Time Library}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}\{\{noshy\}\}`\#include \textless{}time.h\textgreater{}`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Variable Types}}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \{\{noshy\}\}`time\_t` & \{\{noshy\}\}Stores the calendar time. \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \{\{noshy\}\}`struct tm *x;` & \{\{noshy\}\}Stores a time \& date breakdown. \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{noshy\}\}{\emph{tm structure members:}}} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \{\{noshy\}\}`int tm\_sec` & Seconds, 0 to 59. \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} \{\{noshy\}\}`int tm\_min` & Minutes, 0 to 59. \tn % Row Count 11 (+ 2) % Row 7 \SetRowColor{white} \{\{noshy\}\}`int tm\_hour` & Hours, 0 to 23. \tn % Row Count 13 (+ 2) % Row 8 \SetRowColor{LightBackground} \{\{noshy\}\}`int tm\_mday` & Day of the month, 1 to 31. \tn % Row Count 15 (+ 2) % Row 9 \SetRowColor{white} \{\{noshy\}\}`int tm\_mon` & Month, 0 to 11. \tn % Row Count 17 (+ 2) % Row 10 \SetRowColor{LightBackground} \{\{noshy\}\}`int tm\_year` & Years since 1900. \tn % Row Count 19 (+ 2) % Row 11 \SetRowColor{white} \{\{noshy\}\}`int tm\_wday` & Day of the week, 0 to 6. \tn % Row Count 21 (+ 2) % Row 12 \SetRowColor{LightBackground} \{\{noshy\}\}`int tm\_yday` & Day of the year, 0 to 365. \tn % Row Count 23 (+ 2) % Row 13 \SetRowColor{white} \{\{noshy\}\}`int tm\_isdst` & Daylight saving time. \tn % Row Count 25 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{bt\}\}{\bf{Functions}}} \tn % Row Count 26 (+ 1) % Row 15 \SetRowColor{white} \{\{noshy\}\}`time(NULL)` & \{\{noshy\}\}Returns unix epoch time (seconds since 1/Jan/1970.) \tn % Row Count 29 (+ 3) % Row 16 \SetRowColor{LightBackground} \{\{noshy\}\}`time(\&time\_t);` & \{\{noshy\}\}Stores the current time in a `time\_t` variable. \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{The Time Library (cont)}} \tn % Row 17 \SetRowColor{LightBackground} \{\{noshy\}\}`ctime(\&time\_t)` & \{\{noshy\}\}Returns a `time\_t` variable as a string. \tn % Row Count 3 (+ 3) % Row 18 \SetRowColor{white} \{\{noshy\}\}`x = localtime( \&time\_t);` & \{\{noshy\}\}Breaks `time\_t` down into `struct tm` members. \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.8 cm} x{5.2 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Unary Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\emph{by descending evaluation precedence}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{bt\}\}\{\{nobreak\}\}`+a` & \{\{bt\}\}\{\{noshy\}\}Sum of `0` (zero) and `a`. (0 + a) \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`-a` & \{\{noshy\}\}Difference of `0` (zero) and `a`. (0 - a) \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`!a` & \{\{noshy\}\}Complement (logical NOT) of `a`. (\textasciitilde{}a) \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \{\{nobreak\}\}`\textasciitilde{}a` & \{\{noshy\}\}Binary ones complement (bitwise NOT) of `a`. (\textasciitilde{}a) \tn % Row Count 10 (+ 3) % Row 5 \SetRowColor{white} \{\{nobreak\}\}`++a` & \{\{noshy\}\}Increment of `a` by `1`. (a = a + 1) \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}`-{}-a` & \{\{noshy\}\}Decrement of `a` by `1`. (a = a - 1) \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \{\{nobreak\}\}`a++` & \{\{noshy\}\}Returns `a` then increments `a` by `1`. (a = a + 1) \tn % Row Count 17 (+ 3) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}`a-{}-` & \{\{noshy\}\}Returns `a` then decrements `a` by `1`. (a = a - 1) \tn % Row Count 20 (+ 3) % Row 9 \SetRowColor{white} \{\{nobreak\}\}`(type)a` & \{\{noshy\}\}Typecasts `a` as `type`. \tn % Row Count 22 (+ 2) % Row 10 \SetRowColor{LightBackground} \{\{nobreak\}\}`\&a;` & \{\{noshy\}\}Memory location of `a`. \tn % Row Count 24 (+ 2) % Row 11 \SetRowColor{white} \{\{nobreak\}\}`sizeof(a)` & \{\{noshy\}\}Memory size of `a` (or `type`) in bytes. \tn % Row Count 26 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Binary Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\emph{by descending evaluation precedence}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{bt\}\}\{\{nobreak\}\}`a * b;` & \{\{bt\}\}\{\{noshy\}\}Product of `a` and `b`. (a × b) \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`a / b;` & \{\{noshy\}\}Quotient of dividend `a` and divisor `b`. Ensure divisor is non-zero. (a ÷ b) \tn % Row Count 7 (+ 4) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`a \% b;` & \{\{noshy\}\}Remainder of {\emph{integers}} dividend `a` and divisor `b`. \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{nobreak\}\}`a + b;` & \{\{noshy\}\}Sum of `a` and `b`. \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} \{\{nobreak\}\}`a - b;` & \{\{noshy\}\}Difference of `a` and `b`. \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}`a \textless{}\textless{} b;` & \{\{noshy\}\}Left bitwise shift of `a` by `b` places. (a × 2\textasciicircum{}b\textasciicircum{}) \tn % Row Count 17 (+ 3) % Row 7 \SetRowColor{white} \{\{nobreak\}\}`a \textgreater{}\textgreater{} b;` & \{\{noshy\}\}Right bitwise shift of `a` by `b` places. (a × 2\textasciicircum{}-b\textasciicircum{}) \tn % Row Count 20 (+ 3) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}`a \textless{} b;` & \{\{noshy\}\}Less than. True if `a` is less than `b` and false otherwise. \tn % Row Count 23 (+ 3) % Row 9 \SetRowColor{white} \{\{nobreak\}\}`a \textless{}= b;` & \{\{noshy\}\}Less than or equal to. True if `a` is less than or equal to `b` and false otherwise. (a ≤ b) \tn % Row Count 28 (+ 5) % Row 10 \SetRowColor{LightBackground} \{\{nobreak\}\}`a \textgreater{} b;` & \{\{noshy\}\}Greater than. True if `a` is greater than than `b` and false otherwise. \tn % Row Count 32 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Binary Operators (cont)}} \tn % Row 11 \SetRowColor{LightBackground} \{\{nobreak\}\}`a \textgreater{}= b;` & \{\{noshy\}\}Greater than or equal to. True if `a` is greater than or equal to `b` and false otherwise. (a ≥ b) \tn % Row Count 5 (+ 5) % Row 12 \SetRowColor{white} \{\{nobreak\}\}`a == b;` & \{\{noshy\}\}Equality. True if `a` is equal to `b` and false otherwise. (a ⇔ b) \tn % Row Count 9 (+ 4) % Row 13 \SetRowColor{LightBackground} \{\{nobreak\}\}`a != b;` & \{\{noshy\}\}Inequality. True if `a` is not equal to `b` and false otherwise. (a ≠ b) \tn % Row Count 13 (+ 4) % Row 14 \SetRowColor{white} \{\{nobreak\}\}`a \& b;` & \{\{noshy\}\}Bitwise AND of `a` and `b`. (a ⋂ b) \tn % Row Count 15 (+ 2) % Row 15 \SetRowColor{LightBackground} \{\{nobreak\}\}`a \textasciicircum{} b;` & \{\{noshy\}\}Bitwise exclusive-OR of `a` and `b`. (a ⊕ b) \tn % Row Count 18 (+ 3) % Row 16 \SetRowColor{white} \{\{nobreak\}\}`a | b;` & \{\{noshy\}\}Bitwise inclusive-OR of `a` and `b`. (a ⋃ b) \tn % Row Count 21 (+ 3) % Row 17 \SetRowColor{LightBackground} \{\{nobreak\}\}`a \&\& b;` & \{\{noshy\}\}Logical AND. True if both `a` and `b` are non-zero. (Logical AND) (a ⋂ b) \tn % Row Count 25 (+ 4) % Row 18 \SetRowColor{white} \{\{nobreak\}\}`a || b;` & \{\{noshy\}\}Logical OR. True if either `a` or `b` are non-zero. (Logical OR) (a ⋃ b) \tn % Row Count 29 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Ternary \& Assignment Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{noshy\}\}{\emph{by descending evaluation precedence}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \{\{bt\}\}\{\{nobreak\}\}`x ? a : b;` & \{\{bt\}\}\{\{noshy\}\}Evaluates `a` if `x` evaluates as true or `b` otherwise. (if(x)\{ a; \} else \{ b; \}) \tn % Row Count 6 (+ 5) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`x = a;` & \{\{noshy\}\}Assigns value of `a` to `x`. \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`a *= b;` & \{\{noshy\}\}Assigns product of `a` and `b` to `a`. (a = a × b) \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} \{\{nobreak\}\}`a /= b;` & \{\{noshy\}\}Assigns quotient of dividend `a` and divisor `b` to `a`. (a = a ÷ b) \tn % Row Count 15 (+ 4) % Row 5 \SetRowColor{white} \{\{nobreak\}\}`a \%= b;` & \{\{noshy\}\}Assigns remainder of {\emph{integers}} dividend `a` and divisor `b` to `a`. (a = a mod b) \tn % Row Count 19 (+ 4) % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}`a += b;` & \{\{noshy\}\}Assigns sum of `a` and `b` to `a`. (a = a + b) \tn % Row Count 22 (+ 3) % Row 7 \SetRowColor{white} \{\{nobreak\}\}`a -= b;` & \{\{noshy\}\}Assigns difference of `a` and `b` to `a`. (a = a - b) \tn % Row Count 25 (+ 3) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}`a \textless{}\textless{}= b;` & \{\{noshy\}\}Assigns left bitwise shift of `a` by `b` places to `a`. (a = a × 2\textasciicircum{}b\textasciicircum{}) \tn % Row Count 29 (+ 4) % Row 9 \SetRowColor{white} \{\{nobreak\}\}`a \textgreater{}\textgreater{}= b;` & \{\{noshy\}\}Assigns right bitwise shift of `a` by `b` places to `a`. (a = a × 2\textasciicircum{}-b\textasciicircum{}) \tn % Row Count 33 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Ternary \& Assignment Operators (cont)}} \tn % Row 10 \SetRowColor{LightBackground} \{\{nobreak\}\}`a \&= b;` & \{\{noshy\}\}Assigns bitwise AND of `a` and `b` to `a`. (a = a ⋂ b) \tn % Row Count 3 (+ 3) % Row 11 \SetRowColor{white} \{\{nobreak\}\}`a \textasciicircum{}= b;` & \{\{noshy\}\}Assigns bitwise exclusive-OR of `a` and `b` to `a`. (a = a ⊕ b) \tn % Row Count 7 (+ 4) % Row 12 \SetRowColor{LightBackground} \{\{nobreak\}\}`a |= b;` & \{\{noshy\}\}Assigns bitwise inclusive-OR of `a` and `b` to `a`. (a = a ⋃ b) \tn % Row Count 11 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{C Cheatsheet by Ashlyn Black}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\{\{ar\}\}\{\{link="http://ashlynblack.com"\}\}ashlynblack.com\{\{/link\}\}% Row Count 2 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}