Skip to content
Snippets Groups Projects
Commit f42af9fa authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Nachbereitung 16.1.2020

parent 9e089bf0
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char **name = malloc (3 * sizeof (char *));
name[0] = "Anton";
name[1] = "Berthold";
name[2] = "Caesar";
char **new_name = malloc (4 * sizeof (char*));
for (int i = 0; i < 3; i++)
new_name[i] = name[i];
name = new_name; /* Speicherleck: Array wurde nicht freigegeben! */
name[3] = "Dieter";
for (int i = 0; i < 4; i++)
printf ("%s\n", name[i]);
free (name);
free (new_name);
return 0;
}
../common/hello-gtk.png
\ No newline at end of file
No preview for this file type
......@@ -72,6 +72,7 @@
\color{red}
\item[6.3] Unions
\item[6.4] Virtuelle Methoden
\color{black}
\item[6.5] Beispiel: Graphische Benutzeroberfläche (GUI)
\item[6.6] Ausblick: C++
\end{itemize}
......@@ -820,6 +821,8 @@
\end{itemize}
\end{frame}
\iffalse
\subsection{Beispiel: Graphische Benutzeroberfläche (GUI)}
\begin{frame}[fragile]
......@@ -932,4 +935,6 @@
\end{frame}
\fi
\end{document}
#include <stdio.h>
typedef struct
{
int type;
} t_base;
typedef struct
{
int type;
int content;
} t_integer;
typedef struct
{
int type;
char *content;
} t_string;
int main (void)
{
t_integer i = { 1, 42 };
t_string s = { 2, "Hello, world!" };
t_base *object[] = { &i, &s };
for (int i = 0; i < 2; i++)
if (object[i]->type == 1)
printf ("Integer: %d\n", object[i]->content);
else if (object[i]->type == 2)
printf ("String: \"%s\"\n", object[i]->content);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment