Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 2014ss
  • 2015ss
  • 2016ss
  • 2017ss
  • 2018ss
  • 2019ss
  • 2020ss
  • 2021ss
  • 2022ss
  • 2023ss
  • 2024ss
  • 2025ss
12 results

Target

Select target project
  • pgerwinski/bs
  • cloepke/bs
  • khaleeliyeh/bs
3 results
Select Git revision
  • 2014ss
  • 2015ss
  • 2016ss
  • 2017ss
  • 2018ss
  • 2019ss
  • 2020ss
  • 2021ss
  • 2022ss
  • 2023ss
10 results
Show changes

Commits on Source 147

47 additional commits have been omitted to prevent performance issues.
Showing
with 0 additions and 1783 deletions
../common/IMG_20160404_122320.jpg
\ No newline at end of file
../common/Operating_system_placement-de.svg
\ No newline at end of file
File deleted
File deleted
% cpp-20161010.pdf - Lecture Slides on Advanced Software Development in C++
% Copyright (C) 2012, 2013, 2015, 2016 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
\documentclass[10pt,t]{beamer}
\usepackage{pgslides}
\usepackage{tikz}
\newrgbcolor{orange}{0.7 0.2 0.0}
\newcommand{\underconstruction}{%
\begin{picture}(0,0)
\put(6,0.3){\makebox(0,0)[b]{\includegraphics[width=1.5cm]{Zeichen_123.pdf}}}
\put(6,0.0){\makebox(0,0)[t]{\shortstack{Änderungen\\vorbehalten}}}
\end{picture}}
\title{Vertiefung Software-Entwicklung in C++}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{10.\ Oktober 2016}
\begin{document}
\maketitleframe
\date{\begin{picture}(0,0)
\color{red}
\put(0.65,1.05){\makebox(0,0)[t]{$\underbrace{\rule{1.45cm}{0pt}}_{%
\mbox{\emph{rerum naturalium\/} = der natürlichen Dinge (lat.)}}$}}
\end{picture}%
10.\ Oktober 2015}
\maketitleframe
\author{{\color{gray}Prof.\ Dr.\ rer.\ nat.\ }Peter {\color{gray}Gerwinski}}
\maketitleframe
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{10.\ Oktober 2016}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\begin{itemize}
\color{red}
\item[1.1] Was ist C?
\item[1.2] Was ist C++?
\end{itemize}
\item[\textbf{2}] \textbf{\color{red}Wiederholung: Programmieren in C}
\item[\textbf{3}] \textbf{Einführung in C++}
\underconstruction
\item[\textbf{4}] \textbf{Standard-Bibliotheken (STL)}
\item[\textbf{5}] \textbf{C++11}
\item[\textbf{6}] \textbf{Plug-In-Architekturen}
\item[\textbf{7}] \textbf{Die Boost-Bibliothek}
\end{itemize}
\end{frame}
\section{Einführung}
\subsection{Was ist C?}
\begin{frame}
\showsection
\showsubsection
Etabliertes Profi-Werkzeug
\begin{itemize}
\item
kleinster gemeinsamer Nenner für viele Plattformen\\
\begin{picture}(0,1)
\color{red}
\put(7.2,0.6){\tikz{\draw[-latex](0.0,0.0)--(0.0,0.4);}}
\put(7.2,0.5){\makebox(0,0)[t]{\color{black}Hardware und/oder Betriebssystem}}
\end{picture}
\item
Hardware direkt ansprechen und effizient einsetzen
\item
\dots\ bis hin zu komplexen Software-Projekten
\medskip
\arrowitem
Man kann Computer vollständig beherrschen.
\end{itemize}
\end{frame}
\begin{frame}
\showsection
\showsubsection
\begin{picture}(0,0)
\put(5.3,-3){\makebox(0,0)[tl]{\begin{minipage}{7cm}
\emph{C makes it easy to shoot yourself in the foot.}
\begin{flushright}
Bjarne Stroustrup, ca.~1986\\
\href{http://www.stroustrup.com/bs_faq.html\#really-say-that}%
{\nolinkurl{http://www.stroustrup.com/bs_faq.html}\\
\nolinkurl{\#really-say-that}}
\end{flushright}
\end{minipage}}}
\end{picture}%
Etabliertes Profi-Werkzeug
\begin{itemize}
\item
kleinster gemeinsamer Nenner für viele Plattformen
\item
Hardware direkt ansprechen und effizient einsetzen
\item
\dots\ bis hin zu komplexen Software-Projekten
\item
leistungsfähig, aber gefährlich
\end{itemize}
\medskip
"`High-Level-Assembler"'
\begin{itemize}
\item
kein "`Fallschirm"'
\item
kompakte Schreibweise
\end{itemize}
\medskip
Unix-Hintergrund
\begin{itemize}
\item
Baukastenprinzip
\item
konsequente Regeln
\item
kein "`Fallschirm"'
\end{itemize}
\end{frame}
\subsection{Was ist C++?}
\begin{frame}
\showsection
\showsubsection
\begin{picture}(0,0)
\put(6.3,-0.2){\makebox(0,0)[tl]{\begin{minipage}{6cm}
\emph{C++ is a better C.}
\begin{flushright}
Bjarne Stroustrup, Autor von C++\\
\url{http://www.stroustrup.com/C++.html}
\end{flushright}
\end{minipage}}}
\put(5.3,-3){\makebox(0,0)[tl]{\begin{minipage}{7cm}
\emph{C makes it easy to shoot yourself in the foot;\\
C++ makes it harder, but when you do\\
it blows your whole leg off.}
\begin{flushright}
Bjarne Stroustrup, Autor von C++, ca.~1986\\
\href{http://www.stroustrup.com/bs_faq.html\#really-say-that}%
{\nolinkurl{http://www.stroustrup.com/bs_faq.html}\\
\nolinkurl{\#really-say-that}}
\end{flushright}
\end{minipage}}}
\end{picture}%
Etabliertes Profi-Werkzeug
\begin{itemize}
\item
kompatibel zu C
\end{itemize}
\medskip
C++ unterstützt
\begin{itemize}
\item
\newterm{objektorientierte\\
Programmierung}
\item
\newterm{Datenabstraktion}
\item
\newterm{generische\\
Programmierung}
\end{itemize}
\end{frame}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\begin{itemize}
\color{medgreen}
\item[1.1] Was ist C?
\item[1.2] Was ist C++?
\end{itemize}
\item[\textbf{2}] \textbf{Wiederholung: Programmieren in C}
\begin{itemize}
\color{red}
\item[2.1] Hello, world!
\item[2.2] Programme compilieren und ausführen
\item[2.3] Elementare Aus- und Eingabe
\item[2.4] Elementares Rechnen
\item[2.5] Verzweigungen
\item[2.6] Schleifen
\item[2.7] Seiteneffekte
\item[2.8] Strukturierte Programmierung
% \item[2.9] Funktionen
% \item[2.10] Zeiger
% \item[2.11] Arrays und Strings
% \item[2.12] Strukturen
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
\item[\textbf{3}] \textbf{Einführung in C++}
\underconstruction
% \item[\textbf{4}] \textbf{Standard-Bibliotheken (STL)}
% \item[\textbf{5}] \textbf{C++11}
% \item[\textbf{6}] \textbf{Plug-In-Architekturen}
% \item[\textbf{7}] \textbf{Die Boost-Bibliothek}
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
\vspace*{-1cm}
\end{frame}
\section{Wiederholung: Programmieren in C}
\subsection{Hello, world!}
\begin{frame}[fragile]
\showsection
\showsubsection
Text ausgeben
\bigskip
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
printf ("Hello, world!\n");
return 0;
}
\end{lstlisting}
\end{frame}
\subsection{Programme compilieren und ausführen}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}[style=terminal]
$ ¡gcc hello-1.c -o hello-1¿
$ ¡./hello-1¿
Hello, world!
$
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}[style=terminal]
$ ¡gcc -Wall -O hello-1.c -o hello-1¿
$ ¡./hello-1¿
Hello, world!
$
\end{lstlisting}
\pause
\begin{picture}(0,0)
\color{red}
\put(3.0,0.5){\tikz{\draw[-latex](0.0,0.0)--(-3.0,1.0);}}
\put(4.0,0.3){\makebox(0,0)[tl]{\begin{minipage}[t]{6cm}
\begin{tabular}{ll}
\lstinline[style=cmd]{-Wall} & alle Warnungen einschalten\\
\lstinline[style=cmd]{-O} & optimieren\\
\lstinline[style=cmd]{-O3} & maximal optimieren\\
\lstinline[style=cmd]{-Os} & Codegröße optimieren\\[\smallskipamount]
\dots & gcc hat \emph{sehr viele\/} Optionen.
\end{tabular}
\end{minipage}}}
\end{picture}
\end{frame}
\subsection{Elementare Aus- und Eingabe}
\begin{frame}[fragile]
\showsubsection
Wert ausgeben
\bigskip
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
printf ("Die Antwort lautet: %d\n", 42);
return 0;
}
\end{lstlisting}
\begin{picture}(0,0)
\color{red}
\put(5.3,0.65){\tikz{\draw[-latex](0.0,0.0)--(-0.5,0.5);}}
\put(5.9,0.35){\begin{minipage}[t]{6cm}
Formatspezifikation "`d"': "`dezimal"'\pause\\[\smallskipamount]
Weitere Formatspezifikationen:\\
siehe Online-Dokumentation\\
(z.\,B.\ man 3 printf),\\
Internet-Recherche oder Literatur
\end{minipage}}
\end{picture}
\end{frame}
\begin{frame}[fragile]
\showsubsection
Wert einlesen
\bigskip
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
double a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%lf", &a);
printf ("Ihre Antwort war: %lf\n", a);
return 0;
}
\end{lstlisting}
\begin{picture}(0,0)
\color{red}
\put(3.4,1.8){\tikz{\draw[-latex](0.0,0.0)--(-3.5,0);}}
\put(7.0,1.9){\begin{minipage}[t]{5cm}
Formatspezifikation "`lf"':\\
"`long floating-point"'
\end{minipage}}
\end{picture}
\end{frame}
\subsection{Elementares Rechnen}
\begin{frame}[fragile]
\showsubsection
Wert an Variable zuweisen
\bigskip
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
int a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%d", &a);
a = 2 * a;
printf ("Das Doppelte ist: %d\n", a);
return 0;
}
\end{lstlisting}
\end{frame}
\subsection{Verzweigungen}
\begin{frame}[fragile]
\showsubsection
\begin{minipage}[t]{6cm}
\lstinline{if}-Verzweigung
\bigskip
\begin{lstlisting}[gobble=6]
if (b != 0)
printf ("%d\n", a / b);
\end{lstlisting}
\end{minipage}\pause
\begin{minipage}[t]{6cm}
\textbf{Wahrheitswerte} in C: \textbf{numerisch}\\[\medskipamount]
0 steht für \emph{falsch (false)},\\
$\ne 0$ steht für \emph{wahr (true)}.
\bigskip
\begin{lstlisting}[gobble=6]
if (b)
printf ("%d\n", a / b);
\end{lstlisting}
\end{minipage}
\end{frame}
\subsection{Schleifen}
\begin{frame}[fragile]
\showsubsection
\begin{minipage}[t]{6cm}
\lstinline{while}-Schleife
\bigskip
\begin{lstlisting}[gobble=6]
a = 1;
while (a <= 10)
{
printf ("%d\n", a);
a = a + 1;
}
\end{lstlisting}
\end{minipage}\pause
\begin{minipage}[t]{6cm}
\lstinline{for}-Schleife
\bigskip
\begin{lstlisting}[gobble=6]
for (a = 1; a <= 10; a = a + 1)
printf ("%d\n", a);
\end{lstlisting}
\vspace{1.5cm}
\pause
\lstinline{do}-\lstinline{while}-Schleife
\bigskip
\begin{lstlisting}[gobble=6]
a = 1;
do
{
printf ("%d\n", a);
a = a + 1;
}
while (a <= 10);
\end{lstlisting}
\end{minipage}
\end{frame}
\subsection{Seiteneffekte}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
printf ("%d\n", 42);
"\n";
return 0;
}
\end{lstlisting}
\pause
\begin{picture}(0,0)
\color{red}
\put(1.8,1.35){\tikz{\draw[-latex](0.0,0.0)--(-1.7,0);}}
\put(3.6,1.35){\makebox(0,0)[l]{Ausdruck als Anweisung: Wert wird ignoriert}}
\pause
\put(3.15,1.40){\tikz{\draw[-latex](0.0,0.0)--(-0.4,0.2);}}
\end{picture}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
int a = printf ("%d\n", 42);
printf ("%d\n", a);
return 0;
}
\end{lstlisting}
\pause
\bigskip
\begin{lstlisting}[style=terminal]
$ ¡gcc -Wall -O side-effects-1.c -o side-effects-1¿
$ ¡./side-effects-1¿
42
3
$
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
int a = printf ("%d\n", 42);
printf ("%d\n", a);
return 0;
}
\end{lstlisting}
\begin{itemize}
\item
\lstinline{printf()} ist eine Funktion.
\pause
\item
"`Haupteffekt"': Wert zurückliefern\\
(hier: Anzahl der ausgegebenen Zeichen)
\pause
\item
\newterm{Seiteneffekt\/}: Ausgabe
\end{itemize}
\end{frame}
\addtocounter{subsection}{-1}
\subsection{Seiteneffekte \protect\color{gray}bei Operatoren}
\begin{frame}[fragile]
\showsubsection
\begin{minipage}[t]{6cm}
Unäre Operatoren:
\begin{itemize}
\item
Negation: \lstinline{-foo}
\item
{\only<2->{\color{red}}Funktionsaufruf}: \lstinline{foo ()}
\item
{\only<2->{\color{red}}Post-Inkrement}: \lstinline{foo++}
\item
{\only<2->{\color{red}}Post-Dekrement}: \lstinline{foo--}
\item
{\only<2->{\color{red}}Prä-Inkrement}: \lstinline{++foo}
\item
{\only<2->{\color{red}}Prä-Dekrement}: \lstinline{--foo}
\end{itemize}
\medskip
Binäre Operatoren:
\begin{itemize}
\item
Rechnen: \lstinline{+ - * / %}
\item
Vergleich: \lstinline{== != < > <= >=}
\item
{\only<2->{\color{red}}Zuweisung}: \lstinline{= += -= *= /= %=}
\item
Ignorieren: \lstinline{,}
\end{itemize}
\pause
\medskip
{\color{red}rot = mit Seiteneffekt}
\end{minipage}
\pause
\begin{minipage}[t]{6cm}
\vspace{-\bigskipamount}
\begin{lstlisting}
int i;
\end{lstlisting}
\bigskip
\begin{lstlisting}
i = 0;
while (i < 10)
{
printf ("%d\n", i);
i++;
}
\end{lstlisting}
\bigskip
\pause
\begin{lstlisting}
for (i = 0; i < 10; i++)
printf ("%d\n", i);
\end{lstlisting}
\bigskip
\pause
\begin{lstlisting}
i = 0;
while (i < 10)
printf ("%d\n", i++);
\end{lstlisting}
\bigskip
\pause
\begin{lstlisting}
for (i = 0; i < 10; printf ("%d\n", i++));
\end{lstlisting}
\end{minipage}
\vspace*{-1cm}
\end{frame}
\subsection{Strukturierte Programmierung}
\begin{frame}[fragile]
\visible<4->{\showsubsection}
\begin{minipage}[t]{6cm}
\begin{onlyenv}<2->
\begin{lstlisting}[gobble=8]
i = 0;
while (1)
{
if (i >= 10)
break;
printf ("%d\n", i++);
}
\end{lstlisting}
\end{onlyenv}
\strut
\bigskip
\begin{onlyenv}<3->
\begin{lstlisting}[gobble=8]
i = 0;
loop:
if (i >= 10)
goto endloop;
printf ("%d\n", i++);
goto loop;
endloop:
\end{lstlisting}
\end{onlyenv}
\end{minipage}
\begin{minipage}[t]{6cm}
\vspace{-\bigskipamount}
\begin{lstlisting}
int i;
\end{lstlisting}
\bigskip
\begin{lstlisting}
i = 0;
while (i < 10)
{
printf ("%d\n", i);
i++;
}
\end{lstlisting}
\bigskip
\begin{lstlisting}
for (i = 0; i < 10; i++)
printf ("%d\n", i);
\end{lstlisting}
\bigskip
\begin{lstlisting}
i = 0;
while (i < 10)
printf ("%d\n", i++);
\end{lstlisting}
\bigskip
\begin{lstlisting}
for (i = 0; i < 10; printf ("%d\n", i++));
\end{lstlisting}
\end{minipage}%
\begin{onlyenv}<5->
\begin{picture}(0,0)
\color{medgreen}
\put(-1.9,-3.0){\mbox{gut}}
\color{orange}
\put(-1.9,-5.2){\begin{minipage}{5cm}
nur, wenn\\
Sie wissen,\\
was Sie tun
\end{minipage}}
\color{red}
\put(-10,-0.5){\mbox{fragwürdig}}
\put(-9.3,-4.2){\begin{minipage}[t]{5cm}
sehr fragwürdig\\[\smallskipamount]
\footnotesize(siehe z.\,B.:\\
http://xkcd.com/292/)
\end{minipage}}
\end{picture}
\end{onlyenv}
\vspace*{-1cm}
\end{frame}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\begin{itemize}
\color{medgreen}
\item[1.1] Was ist C?
\item[1.2] Was ist C++?
\end{itemize}
\item[\textbf{2}] \textbf{Wiederholung: Programmieren in C}
\begin{itemize}
\color{medgreen}
\item[2.1] Hello, world!
\item[2.2] Programme compilieren und ausführen
\item[2.3] Elementare Aus- und Eingabe
\item[2.4] Elementares Rechnen
\item[2.5] Verzweigungen
\item[2.6] Schleifen
\item[2.7] Seiteneffekte
\item[2.8] Strukturierte Programmierung
% \item[2.9] Funktionen
% \item[2.10] Zeiger
% \item[2.11] Arrays und Strings
% \item[2.12] Strukturen
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
\item[\textbf{3}] \textbf{Einführung in C++}
\underconstruction
% \item[\textbf{4}] \textbf{Standard-Bibliotheken (STL)}
% \item[\textbf{5}] \textbf{C++11}
% \item[\textbf{6}] \textbf{Plug-In-Architekturen}
% \item[\textbf{7}] \textbf{Die Boost-Bibliothek}
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
\vspace*{-1cm}
\end{frame}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\begin{itemize}
\color{medgreen}
\item[1.1] Was ist C?
\item[1.2] Was ist C++?
\end{itemize}
\item[\textbf{2}] \textbf{Wiederholung: Programmieren in C}
\begin{itemize}
\color{medgreen}
% \item[2.1] Hello, world!
\vspace*{-0.1cm}
\item[\dots]
\item[2.7] Seiteneffekte
\item[2.8] Strukturierte Programmierung
\color{red}
\item[2.9] Funktionen
\item[2.10] Zeiger
\item[2.11] Arrays und Strings
\item[2.12] Strukturen
\item[2.13] Dateien und Fehlerbehandlung
\item[2.14] Parameter des Hauptprogramms
\item[2.15] String-Operationen
% \item[2.16] Bibliotheken
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
\item[\textbf{3}] \textbf{Einführung in C++}
\underconstruction
% \item[\textbf{4}] \textbf{Standard-Bibliotheken (STL)}
% \item[\textbf{5}] \textbf{C++11}
% \item[\textbf{6}] \textbf{Plug-In-Architekturen}
% \item[\textbf{7}] \textbf{Die Boost-Bibliothek}
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
\vspace*{-1cm}
\end{frame}
\subsection{Funktionen}
\begin{frame}[fragile]
\showsubsection
\begin{minipage}[t]{6.5cm}
\vspace{-\medskipamount}
\begin{lstlisting}[gobble=6]
#include <stdio.h>
int answer (void)
{
return 42;
}
void foo (void)
{
printf ("%d\n", answer ());
}
int main (void)
{
foo ();
return 0;
}
\end{lstlisting}
\vspace*{-1cm}
\end{minipage}%
\begin{minipage}[t]{6cm}
\begin{itemize}
\pause
\item
Funktionsdeklaration:\\[\smallskipamount]
Typ Name ( Parameterliste )\\
\{\\
\quad Anweisungen\\
\}
\end{itemize}
\end{minipage}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{minipage}[t]{6.5cm}
\vspace{-\medskipamount}
\begin{lstlisting}[gobble=6]
#include <stdio.h>
void add_verbose (int a, int b)
{
printf ("%d + %d = %d\n", a, b, a + b);
}
int main (void)
{
add_verbose (3, 7);
return 0;
}
\end{lstlisting}
\end{minipage}%
\begin{minipage}[t]{6cm}
\begin{itemize}
\item
Funktionsdeklaration:\\[\smallskipamount]
Typ Name ( Parameterliste )\\
\{\\
\quad Anweisungen\\
\}
\pause
\bigskip
\item
Der Datentyp \lstinline{void}\\
steht für "`nichts"'\\
und \alt<3->{muß}{kann} ignoriert werden.
\end{itemize}
\end{minipage}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{minipage}{6cm}
\begin{lstlisting}[gobble=6]
#include <stdio.h>
int a, b = 3;
void foo (void)
{
b++;
static int a = 5;
int b = 7;
printf ("foo(): "
"a = %d, b = %d\n",
a, b);
a++;
}
\end{lstlisting}
\end{minipage}%
\begin{minipage}{6cm}
\vspace{-1cm}
\begin{lstlisting}[gobble=6]
int main (void)
{
printf ("main(): "
"a = %d, b = %d\n",
a, b);
foo ();
printf ("main(): "
"a = %d, b = %d\n",
a, b);
a = b = 12;
printf ("main(): "
"a = %d, b = %d\n",
a, b);
foo ();
printf ("main(): "
"a = %d, b = %d\n",
a, b);
return 0;
}
\end{lstlisting}
\end{minipage}
\end{frame}
\subsection{Zeiger}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
void calc_answer (int *a)
{
*a = 42;
}
int main (void)
{
int answer;
calc_answer (&answer);
printf ("The answer is %d.\n", answer);
return 0;
}
\end{lstlisting}
\pause
\vspace{-5cm}\hspace{5cm}%
\begin{minipage}{7cm}
\begin{itemize}
\item
\lstinline{*a} ist eine \lstinline{int}.
\pause
\item
unärer Operator \lstinline{*}:\\
Pointer-Dererefenzierung
\pause
\arrowitem
\lstinline{a} ist ein Zeiger (Pointer) auf eine \lstinline{int}.
\pause
\bigskip
\item
unärer Operator \lstinline{&}: Adresse
\end{itemize}
\end{minipage}
\end{frame}
\subsection{Arrays und Strings}
\begin{frame}[fragile]
\showsubsection
Ein Zeiger zeigt auf eine Variable\only<2->{ und deren Nachbarn}.
\bigskip
\pause
\pause
\begin{onlyenv}<1-9>
\begin{lstlisting}[gobble=6]
#include <stdio.h>
int main (void)
{
int prime[5] = { 2, 3, 5, 7, 11 };
int *p = prime;
for (int i = 0; i < 5; i++)
printf ("%d\n", *(p + i));
return 0;
}
\end{lstlisting}
\end{onlyenv}
\begin{onlyenv}<10->
\begin{lstlisting}[gobble=6]
#include <stdio.h>
int main (void)
{
int prime[5] = { 2, 3, 5, 7, 11 };
for (int i = 0; i < 5; i++)
printf ("%d\n", prime[i]);
return 0;
}
\end{lstlisting}
\end{onlyenv}
\pause
\vspace{-3.05cm}\hspace{5.5cm}%
\begin{minipage}{6.5cm}
\begin{itemize}
\item
\lstinline{prime} ist \alt<5->{ein Array}{eine Ansammlung} von\\fünf ganzen Zahlen.
\pause
\pause
\item
\begin{picture}(0,0)
\color{red}
\put(-1.6,0.1){\tikz{\draw[-latex](0.0,0.0)--(-1,0);}}
\end{picture}%
\lstinline{prime} ist ein Zeiger auf eine \lstinline{int}.
\pause
\item
\lstinline{p + i} ist ein Zeiger\\
auf den \lstinline{i}-ten Nachbarn von \lstinline{*p}.
\pause
\item
\lstinline{*(p + i)} ist der \lstinline{i}-te Nachbar von \lstinline{*p}.
\pause
\item
Andere Schreibweise:\\
\lstinline{p[i]} statt \lstinline{*(p + i)}
\end{itemize}
\end{minipage}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
char hello_world[] = "Hello, world!\n";
int i = 0;
while (hello_world[i] != 0)
printf ("%d", hello_world[i++]);
return 0;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
char hello_world[] = "Hello, world!\n";
int i = 0;
while (hello_world[i])
printf ("%d", hello_world[i++]);
return 0;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
char hello_world[] = "Hello, world!\n";
char *p = hello_world;
while (*p)
printf ("%d", *p++);
return 0;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
char hello_world[] = "Hello, world!\n";
char *p = hello_world;
while (*p)
printf ("%c", *p++);
return 0;
}
\end{lstlisting}
\vspace{-1.7cm}\hspace{5cm}%
\begin{minipage}{7cm}
\begin{itemize}
\pause
\item
Ein \lstinline{char} ist eine kleinere \lstinline{int}.
\pause
\item
Ein "`String"' in C ist ein Array von \lstinline{char}s\only<4->{,\\
also ein Zeiger auf \lstinline{char}s}\only<5->{\\
also ein Zeiger auf (kleinere) Integer}.
\pause
\pause
\pause
\item
Der letzte \lstinline{char} muß 0 sein.\\
Er kennzeichnet das Ende des Strings.
\pause
\item
Die Formatspezifikation\\
entscheidet über die Ausgabe:\\[\smallskipamount]
\begin{tabular}{ll}
\lstinline|%d|\hspace*{0.5em}dezimal
& \lstinline|%c|\hspace*{0.5em}Zeichen\\
\lstinline|%x|\hspace*{0.5em}hexadezimal
\pause
& \lstinline|%s|\hspace*{0.5em}String
\end{tabular}
\vspace*{-1cm}
\end{itemize}
\end{minipage}
\end{frame}
\subsection{Strukturen}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
typedef struct
{
char day, month;
int year;
}
date;
int main (void)
{
date today = { 30, 10, 2014 };
printf ("%d.%d.%d\n", today.day, today.month, today.year);
return 0;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\vspace*{0.9mm}
\begin{minipage}[b]{6cm}
\begin{lstlisting}[gobble=6]
#include <stdio.h>
typedef struct
{
char day, month;
int year;
}
date;
void set_date (date *d)
{
(*d).day = 30;
(*d).month = 10;
(*d).year = 2014;
}
\end{lstlisting}
\end{minipage}%
\begin{minipage}[b]{6cm}
\begin{lstlisting}[gobble=6]
int main (void)
{
date today;
set_date (&today);
printf ("%d.%d.%d\n", today.day,
today.month, today.year);
return 0;
}
\end{lstlisting}
\end{minipage}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\vspace*{0.9mm}
\begin{minipage}[b]{6cm}
\begin{lstlisting}[gobble=6]
#include <stdio.h>
typedef struct
{
char day, month;
int year;
}
date;
void set_date (date *d)
{
d->day = 30;
d->month = 10;
d->year = 2014;
}
\end{lstlisting}
\end{minipage}%
\begin{minipage}[b]{6cm}
\hspace*{-1cm}%
\lstinline{foo->bar}
ist Abkürzung für
\lstinline{(*foo).bar}
\vspace{2cm}
\begin{lstlisting}[gobble=6]
int main (void)
{
date today;
set_date (&today);
printf ("%d.%d.%d\n", today.day,
today.month, today.year);
return 0;
}
\end{lstlisting}
\end{minipage}
\end{frame}
\subsection{Dateien und Fehlerbehandlung}
\begin{frame}[fragile]
\showsubsection
\vspace*{-0.2925cm}
\begin{minipage}[t]{6cm}
\begin{onlyenv}<1>
\begin{lstlisting}[gobble=8]
#include <stdio.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
fprintf (f, "Hello, world!\n");
fclose (f);
return 0;
}
\end{lstlisting}
\end{onlyenv}
\begin{onlyenv}<2>
\begin{lstlisting}[gobble=8]
#include <stdio.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
}
return 0;
}
\end{lstlisting}
\end{onlyenv}
\begin{onlyenv}<3>
\begin{lstlisting}[gobble=8]
#include <stdio.h>
#include <errno.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
}
else
fprintf (stderr, "error #%d\n", errno);
return 0;
}
\end{lstlisting}
\end{onlyenv}
\begin{onlyenv}<4>
\begin{lstlisting}[gobble=8]
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
}
else
{
char *msg = strerror (errno);
fprintf (stderr, "%s\n", msg);
}
return 0;
}
\end{lstlisting}
\vspace*{-1cm}
\end{onlyenv}
\begin{onlyenv}<5->
\begin{lstlisting}[gobble=8]
#include <stdio.h>
#include <errno.h>
#include <error.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (!f)
error (-1, errno, "cannot open file");
fprintf (f, "Hello, world!\n");
fclose (f);
return 0;
}
\end{lstlisting}
\end{onlyenv}
\end{minipage}\pause\hspace*{-1.5cm}%
\begin{minipage}[t]{8.5cm}
\bigskip
\only<3->{\bigskip}
\begin{itemize}
\item
Wenn die Datei nicht geöffnet werden kann,\\
gibt \lstinline{fopen()} den Wert \lstinline{NULL} zurück.
\pause
\medskip
\item
\addtolength{\leftskip}{1cm}
Die globale Variable \lstinline{int errno}\\
enthält dann die Nummer des Fehlers.\\
Benötigt: \lstinline{#include <errno.h>}
\pause
\medskip
\only<5->{\bigskip}
\item
Die Funktion \lstinline{strerror()} wandelt \lstinline{errno}\\
in einen Fehlermeldungstext um.\\
Benötigt: \lstinline{#include <string.h>}
\pause
\medskip
\item
\addtolength{\leftskip}{-1.5cm}
Die Funktion \lstinline{error()} gibt eine Fehlermeldung aus\\
und beendet das Programm.\\
Benötigt: \lstinline{#include <error.h>}
\pause
\medskip
\item
\textbf{Niemals Fehler einfach ignorieren!}
\end{itemize}
\addtolength{\leftskip}{0.5cm}
\end{minipage}
\end{frame}
\subsection{Parameter des Hauptprogramms}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
for (int i = 0; i < argc; i++)
printf ("argv[%d] = \"%s\"\n", i, argv[i]);
return 0;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
for (int i = 0; *argv; i++, argv++)
printf ("argv[%d] = \"%s\"\n", i, *argv);
return 0;
}
\end{lstlisting}
\end{frame}
\subsection{String-Operationen}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
#include <string.h>
int main (void)
{
char hello[] = "Hello, world!\n";
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
printf ("%s\n", hello + 7);
printf ("%zd\n", strlen (hello + 7));
hello[5] = 0;
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
return 0;
}
\end{lstlisting}
\vspace*{-1cm}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
#include <string.h>
int main (void)
{
char *anton = "Anton";
char *zacharias = "Zacharias";
printf ("%d\n", strcmp (anton, zacharias));
printf ("%d\n", strcmp (zacharias, anton));
printf ("%d\n", strcmp (anton, anton));
char buffer[100] = "Huber ";
strcat (buffer, anton);
printf ("%s\n", buffer);
return 0;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <stdio.h>
#include <string.h>
int main (void)
{
char buffer[100] = "";
sprintf (buffer, "Die Antwort lautet: %d", 42);
printf ("%s\n", buffer);
char *answer = strstr (buffer, "Antwort");
printf ("%s\n", answer);
printf ("found at: %zd\n", answer - buffer);
return 0;
}
\end{lstlisting}
\end{frame}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\begin{itemize}
\color{medgreen}
\item[1.1] Was ist C?
\item[1.2] Was ist C++?
\end{itemize}
\item[\textbf{2}] \textbf{Wiederholung: Programmieren in C}
\begin{itemize}
\color{medgreen}
% \item[2.1] Hello, world!
\vspace*{-0.1cm}
\item[\dots]
\item[2.7] Seiteneffekte
\item[2.8] Strukturierte Programmierung
\item[2.9] Funktionen
\item[2.10] Zeiger
\item[2.11] Arrays und Strings
\item[2.12] Strukturen
\item[2.13] Dateien und Fehlerbehandlung
\item[2.14] Parameter des Hauptprogramms
\item[2.15] String-Operationen
\color{red}
% \item[2.16] Bibliotheken
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
\item[\textbf{3}] \textbf{Einführung in C++}
\underconstruction
% \item[\textbf{4}] \textbf{Standard-Bibliotheken (STL)}
% \item[\textbf{5}] \textbf{C++11}
% \item[\textbf{6}] \textbf{Plug-In-Architekturen}
% \item[\textbf{7}] \textbf{Die Boost-Bibliothek}
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
\vspace*{-1cm}
\end{frame}
\end{document}
../common/logo-hochschule-bochum-cvh-text.pdf
\ No newline at end of file
../common/logo-hochschule-bochum.pdf
\ No newline at end of file
% pgslides.sty - LaTeX Settings for Lecture Slides
% Copyright (C) 2012, 2013 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
\usepackage[latin1]{inputenc}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{helvet}
\renewcommand*\familydefault{\sfdefault}
\usetheme{default}
\usefonttheme{structurebold}
\setbeamertemplate{navigation symbols}{}
\setbeamersize{text margin left = 0.3cm, text margin right = 0.2cm}
\setbeamertemplate{itemize item}{$\bullet$}
\setbeamertemplate{itemize subitem}{--}
\setbeamerfont{itemize/enumerate subbody}{size=\normalsize}
\setbeamerfont{itemize/enumerate subsubbody}{size=\normalsize}
\setbeamercolor{footline}{fg=gray}
\newcommand{\sep}{~$\cdot$~}
\institute[Hochschule Bochum\sep CVH]{%
\makebox(0,0)[tl]{\includegraphics[scale=0.57]{logo-hochschule-bochum-cvh-text.pdf}}\hfill
\makebox(0,0)[tr]{\includegraphics[scale=0.5]{logo-hochschule-bochum.pdf}}%
}
\iffalse
\setbeamertemplate{footline}{}
\else
\setbeamertemplate{footline}{%
\leavevmode%
\hbox to \textwidth{%
\usebeamercolor{footline}%
\usebeamerfont{footline}%
\iftrue
\strut\hfill
\else
\,\insertshorttitle\sep
\insertshortauthor\sep
\insertshortinstitute\sep
\insertshortdate\hfill
\fi
Folie\,\insertframenumber\sep Seite\,\insertpagenumber\,
}%
\vskip0pt%
}
\fi
\newcommand{\maketitleframe}{%
\begin{frame}[t,plain]
\insertinstitute
\par\vfill
\begin{center}
{\LARGE\color{structure}\inserttitle}\\[2\bigskipamount]
{\large \insertauthor}\\[1.5\bigskipamount]
\insertdate
\end{center}
\end{frame}
}
\usepackage{pstricks}
\newrgbcolor{lightyellow}{0.95 0.85 0.0}
\newrgbcolor{lightorange}{1.0 0.7 0.0}
\newrgbcolor{lightgreen}{0.0 0.8 0.0}
\newrgbcolor{medgreen}{0.0 0.5 0.0}
\newrgbcolor{darkgreen}{0.0 0.3 0.0}
\newrgbcolor{lightred}{1.0 0.7 0.7}
\newrgbcolor{lightgray}{0.85 0.85 0.85}
\definecolor{darkgray}{rgb}{0.4,0.4,0.4}
\newenvironment{experts}{\color{darkgray}}{}
\catcode`\_=13\def_{\kern1pt\rule{0.4em}{0.9pt}\kern1pt}\catcode`\_=8
\catcode`\/=13\def/#1{\ifx#1/\char`\/\kern-2pt\char`\/\else\char`\/#1\fi}\catcode`\/=12
\renewcommand{\url}[1]{{\color{structure}\catcode`~=12\catcode`##=12\catcode`_=13\catcode`/=13\textsf{#1}}}
\usepackage{listings}
\lstset{basicstyle=\color{structure},
language=C,
captionpos=b,
gobble=4,
columns=fullflexible,
aboveskip=0pt,
belowskip=0pt,
moredelim=**[is][\color{structure}]{}{},
moredelim=**[is][\only<2->{\color{structure}}]{}{},
moredelim=**[is][\only<3->{\color{structure}}]{}{},
moredelim=**[is][\only<4->{\color{structure}}]{}{},
moredelim=**[is][\only<5->{\color{structure}}]{}{},
moredelim=**[is][\only<6->{\color{structure}}]{}{},
moredelim=**[is][\only<7->{\color{structure}}]{}{},
moredelim=**[is][\only<8->{\color{structure}}]{}{}}
\lstdefinestyle{terminal}{basicstyle=\ttfamily\color{darkgreen},
language={},
columns=fixed,
moredelim=**[is][\color{red}]{}{},
moredelim=**[is][\color{blendedblue}]{}{},
moredelim=**[is][\sffamily\it\lstset{columns=fullflexible}]{}{}}
\lstdefinestyle{cmd}{basicstyle=\ttfamily\color{red},
language={},
gobble=2,
columns=fixed,
moredelim=**[is][\color{darkgreen}]{}{},
moredelim=**[is][\color{structure}]{}{},
moredelim=**[is][\sffamily\it\lstset{columns=fullflexible}]{}{}}
\lstdefinestyle{shy}{basicstyle=\color{lightgray}}
\setcounter{topnumber}{3}
\renewcommand\topfraction{0.7}
\setcounter{bottomnumber}{3}
\renewcommand\bottomfraction{0.7}
\setcounter{totalnumber}{5}
\renewcommand\textfraction{0.1}
\renewcommand\floatpagefraction{0.9}
\setlength{\unitlength}{1cm}
\newcommand{\protectfile}[1]{#1}
\newcommand{\file}[1]{{\color{structure}\protectfile{#1}}}
\newcommand{\textarrow}{{\boldmath $\longrightarrow$}}
\newcommand{\arrowitem}{\item[\textarrow]}
\newcommand{\newterm}[1]{\emph{\color{darkgreen}#1}}
\newcommand{\BIGskip}{\vspace{1cm}}
\newcommand{\shy}{\color{lightgray}}
\newcommand{\hot}{\color{red}}
\newcommand{\shyhot}{\color{lightred}}
\newcommand{\sectionnonumber}[1]{\section{#1}\addtocounter{section}{-1}}
\def\showsectionnonumber{{\Large\color{structure}\bf\secname\par}\bigskip}
\def\showsection{\hbox{\Large\color{structure}\bf
\vtop{\hbox{\arabic{section}}}\kern1em%
\vtop{\secname}\par}\bigskip}
\newcommand{\subsectionnonumber}[1]{\subsection{#1}\addtocounter{subsection}{-1}}
\def\showsubsectionnonumber{{\large\color{structure}\bf\subsecname\par}\bigskip}
\def\showsubsection{\hbox{\large\color{structure}\bf
\vtop{\hbox{\arabic{section}.\arabic{subsection}}}\kern1em%
\vtop{\subsecname}\par}\bigskip}
\newcommand{\subsubsectionnonumber}[1]{\subsubsection{#1}\addtocounter{subsubsection}{-1}}
\def\showsubsubsectionnonumber{{\normalsize\color{structure}\bf\subsubsecname\par}\bigskip}
\def\showsubsubsection{\hbox{\normalsize\color{structure}\bf
\vtop{\hbox{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}}\kern1em%
\vtop{\subsubsecname}\par}\bigskip}
20170421/photo-20170421-150647.jpg

118 KiB

#include <stdio.h>
int main (void)
{
double a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%lf", a);
printf ("Ihre Antwort war: %lf\n", a);
return 0;
}
File deleted
#include <stdio.h>
int main (void)
{
int prime[5] = { 2, 3, 5, 7, 11 };
int *p = prime;
for (int i = 0; i < 5; i++)
printf ("%d\n", *(p + i));
return 0;
}
#include <stdio.h>
int main (void)
{
int prime[5] = { 2, 3, 5, 7, 11 };
int *p = prime;
for (int i = 0; i < 5; i++)
printf ("%d\n", p + i);
return 0;
}
..
\ No newline at end of file
.
\ No newline at end of file
for x in *.c; do gcc -Wall -O $x -o $(basename $x .c); done
#!/usr/bin/bc -q
1 + 1
quit
Hallo.
Hallo?
Hallo!
20170428/photo-20170428-150100.jpg

114 KiB

#include <stdio.h>
int main (void)
{
char hello_world[] = "Hello, world!\n";
int i = 0;
while (hello_world[i] != 0)
printf ("%d", hello_world[i++]);
return 0;
}