C.tex 6.4 KB

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