2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-25 14:28:05 +02:00
LaTeX-examples/documents/Programmierparadigmen/C.tex

126 lines
6 KiB
TeX
Raw Normal View History

%!TEX root = Programmierparadigmen.tex
2014-02-01 13:46:33 +01:00
\chapter{C}
\index{C|(}
2014-02-01 15:32:13 +01:00
C ist eine imperative Programmiersprache. Sie wurde in vielen Standards
2014-03-09 19:06:23 +01:00
definiert. Die wichtigsten davon sind:
2014-02-01 15:32:13 +01:00
\begin{itemize}
2014-03-09 19:06:23 +01:00
\item C89 wird auch ANSI C genannt.
\item C90 wurde unter ISO 9899:1990 veröffentlicht. Es gibt keine bedeutenden
Unterschiede zwischen C89 und C90, nur ist das eine ein ANSI-Standard
und das andere ein ISO-Standard.
\item C99 wurde unter ISO 9899:1999 veröffentlicht.
\item C11 wurde unter ISO 9899:2011 veröffentlicht.
2014-02-01 15:32:13 +01:00
\end{itemize}
\section{Datentypen}\xindex{Datentypen}
Die grundlegenden C-Datentypen sind
\begin{table}[htp]
\centering
\begin{tabular}{|l|l|}
\hline
\textbf{Typ} & \textbf{Größe} \\ \hline\hline
char & 1 Byte \\ \hline
int & 4 Bytes \\ \hline
float & 4 Bytes \\ \hline
double & 8 Bytes \\ \hline
void & 0 Bytes \\ \hline
\end{tabular}
\end{table}
zusätzlich kann man \texttt{char}\xindex{char} und \texttt{int}\xindex{int}
noch in \texttt{signed}\xindex{signed} und \texttt{unsigned}\xindex{unsigned}
2014-03-09 19:06:23 +01:00
unterscheiden. Diese werden \textit{Modifier}\xindex{Modifier} genannt.
In C gibt es keinen direkten Support für Booleans.
2014-03-02 19:35:37 +01:00
\section{ASCII-Tabelle}\label{sec:ascii-tabelle}
2014-03-09 19:06:23 +01:00
\begin{table}[h]
\centering
2014-03-09 19:06:23 +01:00
\resizebox{0.65\textwidth}{!}{%
\begin{tabular}{|l|l||l|l||l|l||l|l|}
\hline
2014-02-14 09:23:58 +01:00
\textbf{Dez.} & \textbf{Z.} & \textbf{Dez.} & \textbf{Z.} & \textbf{Dez.} & \textbf{Z.} & \textbf{Dez.} & \textbf{Z.} \\ \hline\hline
2014-03-09 19:06:23 +01:00
0 & ~ & 32 & ~ & 64 & @ & 96 & ' \\ \hline
1 & ~ & 33 & ! & 65 & A & 97 & a \\ \hline
2 & ~ & 34 & " & 66 & B & 98 & b \\ \hline
3 & ~ & 35 & \# & 67 & C & 99 & c \\ \hline
4 & ~ & 36 & \$ & 68 & D & 100 & d \\ \hline
5 & ~ & 37 & \% & 69 & E & 101 & e \\ \hline
6 & ~ & 38 & \& & 70 & F & 102 & f \\ \hline
7 & ~ & 39 & ' & 71 & G & 103 & g \\ \hline
8 & ~ & 40 & ( & 72 & H & 104 & h \\ \hline
9 & ~ & 41 & ) & 73 & I & 105 & i \\ \hline
10 & ~ & 42 & * & 74 & J & 106 & j \\ \hline
11 & ~ & 43 & + & 75 & K & 107 & k \\ \hline
12 & ~ & 44 & , & 76 & L & 108 & l \\ \hline
13 & ~ & 45 & - & 77 & M & 109 & m \\ \hline
14 & ~ & 46 & . & 78 & N & 110 & n \\ \hline
15 & ~ & 47 & / & 79 & O & 111 & o \\ \hline
16 & ~ & 48 & 0 & 80 & P & 112 & p \\ \hline
17 & ~ & 49 & 1 & 81 & Q & 113 & q \\ \hline
18 & ~ & 50 & 2 & 82 & R & 114 & r \\ \hline
19 & ~ & 51 & 3 & 83 & S & 115 & s \\ \hline
20 & ~ & 52 & 4 & 84 & T & 116 & t \\ \hline
21 & ~ & 53 & 5 & 85 & U & 117 & u \\ \hline
22 & ~ & 54 & 6 & 86 & V & 118 & v \\ \hline
23 & ~ & 55 & 7 & 87 & W & 119 & w \\ \hline
24 & ~ & 56 & 8 & 88 & X & 120 & x \\ \hline
25 & ~ & 57 & 9 & 89 & Y & 121 & y \\ \hline
26 & ~ & 58 & : & 90 & Z & 122 & z \\ \hline
27 & ~ & 59 & ; & 91 & $[$ & 123 & \{ \\ \hline
28 & ~ & 60 & < & 92 & \textbackslash & 124 & | \\ \hline
29 & ~ & 61 & = & 93 & $]$ & 125 & \} \\ \hline
30 & ~ & 62 & > & 94 & \textasciicircum & 126 & $\sim$ \\ \hline
31 & ~ & 63 & ? & 95 & \_ & 127 & DEL \\ \hline
\end{tabular}
2014-03-09 19:06:23 +01:00
}
\end{table}
2014-02-01 13:46:33 +01:00
\section{Syntax}
2014-03-09 19:06:23 +01:00
\section{Präzedenzregeln}
\begin{tabbing}
\textbf{A} \=\enquote{[name] is a\dots}\\
\>\textbf{B.1} \=prenthesis {\color{red}$( )$}\\
\>\textbf{B.2} \>postfix operators:\\
\> \>\textbf{B.2.1} \={\color{red}$( )$} \=\enquote{\dots function returning\dots}\\
\> \>\textbf{B.2.2} \>{\color{red}$[ ]$} \>\enquote{\dots array of\dots}\\
\>\textbf{B.3} \>prefix operator: {\color{red}*} \enquote{\dots pointer to\dots}\\
\>\textbf{B.4} \>prefix operator {\color{red}*} and {\color{red}\texttt{const} / \texttt{volatile}} modifier:\\
\> \>\enquote{\dots [modifier] pointer to\dots}\\
\>\textbf{B.5} \>{\color{red}\texttt{const} / \texttt{volatile}} modifier next to type specifier:\\
\> \>\enquote{\dots [modifier] [specifier]}\\
\>\textbf{B.6} \>type specifier: \enquote{\dots [specifier]}
\end{tabbing}
\texttt{static unsigned int* const *(*next)();}
\begin{table}[htp]
\centering
\begin{tabular}{lll}
A & \texttt{next} & next is a \\
B.3 & \texttt{*} & \dots pointer to\dots \\
B.1 & \texttt{( )} & \dots \\
B.2.1 & \texttt{( )} & \dots a function returning\dots \\
B.3 & \texttt{*} & \dots pointer to\dots \\
B.4 & \texttt{*const} & \dots a read-only pointer to\dots \\
B.6 & \texttt{static unsigned int} & \dots static unsigned int. \\
\end{tabular}
\end{table}
2014-02-01 13:46:33 +01:00
\section{Beispiele}
\subsection{Hello World}
Speichere den folgenden Text als \texttt{hello-world.c}:
\inputminted[linenos, numbersep=5pt, tabsize=4, frame=lines, label=hello-world.c]{c}{scripts/c/hello-world.c}
Compiliere ihn mit \texttt{gcc hello-world.c}. Es wird eine ausführbare
Datei namens \texttt{a.out} erzeugt.
2014-02-01 13:46:33 +01:00
2014-03-10 15:39:59 +01:00
\subsection{Pointer}
\inputminted[linenos, numbersep=5pt, tabsize=4]{c}{scripts/c/pointer.c}
Die Ausgabe hier ist \texttt{0 3}.
2014-02-01 13:46:33 +01:00
\index{C|)}