From 8fe919bb9aa7ad602a531650e5fed60e64b7a9e1 Mon Sep 17 00:00:00 2001 From: lukas Date: Wed, 22 Apr 2020 16:17:12 +0200 Subject: [PATCH] Struktur als pointer beispiel Quellen auf Deutsch --- src/main.tex | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main.tex b/src/main.tex index 9083f40..201362b 100644 --- a/src/main.tex +++ b/src/main.tex @@ -163,8 +163,7 @@ struct Adresse { int *nummer; short hausnummer; long plz; -}; - \end{lstlisting} +};\end{lstlisting} Anwendung: \begin{lstlisting} // Variable der Struktur erstellen @@ -172,9 +171,9 @@ struct Adresse adresseKurt; // Zugriff auf die Elemente strcpy(adresseKurt.name, "Kurt Kanns"); adresseKurt.hausnummer = 23; -adresseKurt->nummer = 4; -adresseKurt.plz = 45678; - \end{lstlisting} +int nr = 4; +adresseKurt.nummer = &nr; +adresseKurt.plz = 45678;\end{lstlisting} \framebreak @@ -195,7 +194,7 @@ ADR a1,a2; \item Gesamtlänge der Struktur: sizeof(Struktur) \item Zugriff auf einzelne Komponenten durch\\ Punktnotation: Adresse1.Vorname = “Peter“; - \item Pfeilnotation (->) wenn Komponente ist Pointer + \item Pfeilnotation (->) wenn struct ist Pointer \item Weiteres hinzufügen von Komponenten während der Laufzeit nicht möglich. \end{itemize} \end{frame} @@ -256,12 +255,12 @@ void beispiel() { // Erstellen von root node *root = malloc(sizeof(node)); - root.data = 17; + root->data = 17; // Anhaengen eines Knotens node *secondNode = malloc(sizeof(node)); root->next = secondNode; - secondNode.data = 19; + secondNode->data = 19; } \end{lstlisting} \end{frame} @@ -269,7 +268,24 @@ void beispiel() { %------------------------------------------------ \begin{frame}[fragile]{Struktur als Pointer} - todo + \begin{lstlisting} +struct mystruct { + int data; +}; +typedef struct mystruct mystruct; + +void beispiel(mystruct * str) { + int d = str->data; +} + +int main(){ + mystruct struc; + struc.data = 5; + beispiel(&struc); + + return 0; +} + \end{lstlisting} \end{frame} %------------------------------------------------ @@ -284,7 +300,7 @@ void beispiel() { \appendix - \begin{frame}{References} + \begin{frame}{Quellen} \nocite{*} % Display all references regardless of if they were cited \bibliography{quellen} \bibliographystyle{plain}