einige Rechtschreibfehler ausgebessert
verschoenerungen
This commit is contained in:
parent
8fe919bb9a
commit
ee48380e0a
107
src/main.tex
107
src/main.tex
@ -3,7 +3,7 @@
|
||||
% Struktur und Pointer Referat
|
||||
% 20.04.2020
|
||||
%----------------------------------------------------------------------------------------
|
||||
\usetheme{focus} % Use the Focus theme supplied with the template
|
||||
\usetheme{focus}
|
||||
|
||||
\usepackage[utf8]{inputenc}
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
\usepackage{amsmath}
|
||||
\usepackage{hyperref}
|
||||
\usepackage{graphicx}
|
||||
\usepackage{listings} % Required for better table rules
|
||||
\usepackage{listings}
|
||||
\usepackage{xcolor}
|
||||
|
||||
% Farbdefinitionen
|
||||
@ -51,14 +51,12 @@
|
||||
% TITLE SLIDE
|
||||
%----------------------------------------------------------------------------------------
|
||||
|
||||
\title{Strukturen + Pointer \\ Call by Reference/Value}
|
||||
\title{Strukturen + Pointer}
|
||||
|
||||
\subtitle{mit Anwendungsfälle / Programmierbeispiele}
|
||||
|
||||
\author{Lukas Heiligenbrunner}
|
||||
|
||||
\institute{HTL Steyr \\ Schlüsselhofgasse 63}
|
||||
|
||||
\date{\today}
|
||||
|
||||
%------------------------------------------------
|
||||
@ -68,7 +66,7 @@
|
||||
%------------------------------------------------
|
||||
|
||||
\begin{frame}
|
||||
\maketitle % Automatically created using the information in the commands above
|
||||
\maketitle
|
||||
\end{frame}
|
||||
|
||||
%----------------------------------------------------------------------------------------
|
||||
@ -88,12 +86,16 @@
|
||||
\begin{itemize}
|
||||
\item NULL-Pointer
|
||||
\end{itemize}
|
||||
\pause
|
||||
\item Operator *
|
||||
\begin{itemize}
|
||||
\item definiert einen Pointer
|
||||
\item Wert eines Pointers
|
||||
\end{itemize}
|
||||
\item \& Operator: Adresse einer Variable
|
||||
\item Operator \&
|
||||
\begin{itemize}
|
||||
\item Adresse einer Variable
|
||||
\end{itemize}
|
||||
\end{itemize}
|
||||
\end{frame}
|
||||
|
||||
@ -104,16 +106,16 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
//Variable declaration
|
||||
// Variable definieren
|
||||
int num = 10;
|
||||
|
||||
//Pointer declaration
|
||||
// Pointer definieren
|
||||
int *p;
|
||||
|
||||
//Assigning address of num to the pointer p
|
||||
p = *num;
|
||||
// Adresse von num --> p zuweisen
|
||||
p = #
|
||||
|
||||
printf("Num: %d", &p);
|
||||
printf("Num: %d", *p);
|
||||
return 0;
|
||||
}
|
||||
\end{lstlisting}
|
||||
@ -124,7 +126,7 @@ int main()
|
||||
\begin{frame}{Pointer in Java}
|
||||
\begin{itemize}
|
||||
\item Alle Objekte automatisch Pointer
|
||||
\item Primitives (int, float, double) sind Wert direkt
|
||||
\item Primitives (int, float, double) keine Pointer
|
||||
\end{itemize}
|
||||
\end{frame}
|
||||
|
||||
@ -148,7 +150,7 @@ int main()
|
||||
\item Keyword \textit{struct}
|
||||
\pause
|
||||
\item verbessert Übersicht
|
||||
\item Schritt richtung Objektorientierung
|
||||
\item Schritt Richtung Objektorientierung
|
||||
\item ideal für Listen und Baumstruktur
|
||||
\end{itemize}
|
||||
\end{frame}
|
||||
@ -179,25 +181,38 @@ adresseKurt.plz = 45678;\end{lstlisting}
|
||||
|
||||
Typdefinition mit typedef:
|
||||
\begin{lstlisting}
|
||||
struct Adresse {
|
||||
char name[50];
|
||||
short hausnummer;
|
||||
};
|
||||
typedef struct Adresse Adr;
|
||||
|
||||
Adr a1,a2; // Datentyp Adr
|
||||
\end{lstlisting}
|
||||
|
||||
Kombination:
|
||||
\begin{lstlisting}
|
||||
typedef struct Adresse {
|
||||
char name[50];
|
||||
short hausnummer;
|
||||
} ADR;
|
||||
} Adr;
|
||||
|
||||
ADR a1,a2;
|
||||
Adr a1,a2; // Datentyp Adr
|
||||
\end{lstlisting}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}{Sonstiges}
|
||||
\begin{itemize}
|
||||
\item Strukturtypdeklaration: struct Adresse \{…\};
|
||||
\item Gesamtlänge der Struktur: sizeof(Struktur)
|
||||
\item Zugriff auf einzelne Komponenten durch\\
|
||||
Punktnotation: Adresse1.Vorname = “Peter“;
|
||||
\item Pfeilnotation (->) wenn struct ist Pointer
|
||||
Punktnotation: (Adresse1.Vorname = “Peter“);
|
||||
\pause
|
||||
\item Pfeilnotation (->) wenn struct Pointer
|
||||
\item Gesamtlänge der Struktur: sizeof(Struktur)
|
||||
\item Weiteres hinzufügen von Komponenten während der Laufzeit nicht möglich.
|
||||
\end{itemize}
|
||||
\end{frame}
|
||||
|
||||
%------------------------------------------------
|
||||
|
||||
\begin{frame}[fragile]{Strukturen als Funktionsargument}
|
||||
@ -209,7 +224,7 @@ void testfunc(struct Adresse a){
|
||||
\end{lstlisting}
|
||||
Mit Typedef:
|
||||
\begin{lstlisting}
|
||||
void testfunc(ADR a){
|
||||
void testfunc(Adr a){
|
||||
long plz = a.plz;
|
||||
}
|
||||
\end{lstlisting}
|
||||
@ -220,7 +235,7 @@ void testfunc(ADR a){
|
||||
\begin{frame}[fragile]{Strukturen in Java}
|
||||
\begin{itemize}
|
||||
\item existieren nicht
|
||||
\item stattdessen Objekte
|
||||
\item stattdessen Klassen
|
||||
\end{itemize}
|
||||
\begin{lstlisting}[language=java]
|
||||
public class Adresse
|
||||
@ -243,47 +258,47 @@ public class Adresse
|
||||
|
||||
%------------------------------------------------
|
||||
|
||||
\begin{frame}[fragile]{Verkettete Listen}
|
||||
\begin{frame}[fragile]{Struktur als Pointer}
|
||||
\begin{lstlisting}
|
||||
struct node {
|
||||
int data;
|
||||
struct node* next;
|
||||
struct mystruct {
|
||||
int data;
|
||||
};
|
||||
typedef struct node node;
|
||||
typedef struct MyStruct MyStruct;
|
||||
|
||||
void beispiel() {
|
||||
// Erstellen von root
|
||||
node *root = malloc(sizeof(node));
|
||||
void beispiel(MyStruct * str) {
|
||||
int d = str->data;
|
||||
}
|
||||
|
||||
root->data = 17;
|
||||
int main(){
|
||||
MyStruct struc;
|
||||
struc.data = 5;
|
||||
beispiel(&struc);
|
||||
|
||||
// Anhaengen eines Knotens
|
||||
node *secondNode = malloc(sizeof(node));
|
||||
root->next = secondNode;
|
||||
secondNode->data = 19;
|
||||
return 0;
|
||||
}
|
||||
\end{lstlisting}
|
||||
\end{frame}
|
||||
|
||||
%------------------------------------------------
|
||||
|
||||
\begin{frame}[fragile]{Struktur als Pointer}
|
||||
\begin{frame}[fragile]{Verkettete Listen}
|
||||
\begin{lstlisting}
|
||||
struct mystruct {
|
||||
int data;
|
||||
struct Node {
|
||||
int data;
|
||||
struct node* next;
|
||||
};
|
||||
typedef struct mystruct mystruct;
|
||||
typedef struct Node Node;
|
||||
|
||||
void beispiel(mystruct * str) {
|
||||
int d = str->data;
|
||||
}
|
||||
void beispiel() {
|
||||
// Erstellen von root
|
||||
Node *root = malloc(sizeof(Node));
|
||||
|
||||
int main(){
|
||||
mystruct struc;
|
||||
struc.data = 5;
|
||||
beispiel(&struc);
|
||||
root->data = 17;
|
||||
|
||||
return 0;
|
||||
// Anhaengen eines Knotens
|
||||
Node *secondNode = malloc(sizeof(Node));
|
||||
root->next = secondNode;
|
||||
secondNode->data = 19;
|
||||
}
|
||||
\end{lstlisting}
|
||||
\end{frame}
|
||||
|
Loading…
Reference in New Issue
Block a user