This commit is contained in:
Luca Conte 2023-11-08 12:02:11 +01:00
parent f71cd26460
commit 3b6c8ce2f4
3 changed files with 71 additions and 0 deletions

16
v5.5/malloc.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdlib.h>
int main(void) {
int* i = (int*)malloc(sizeof(int));
*i = 42;
double* d = (double*)malloc(sizeof(double));
*d = *i;
free(i);
i = NULL;
free(d);
d = NULL;
}

26
v5.8/angestellte.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdlib.h>
#include <string.h>
struct angestellter {
char name[41];
struct angestellter* chef;
};
typedef struct angestellter angestellter;
int main(void) {
angestellter asterix = { "Asterix", NULL };
angestellter majestix = { "Majestix", NULL };
angestellter* obelix;
obelix = (angestellter*)malloc(sizeof(angestellter));
strcpy(obelix->name, "Obelix");
asterix.chef = &majestix;
obelix->chef = &majestix;
majestix.chef = &asterix;
free(obelix);
obelix = NULL;
}

29
v5.9/angestellte.c Normal file
View File

@ -0,0 +1,29 @@
#include <stdlib.h>
#include <string.h>
struct angestellter {
char name[41];
struct angestellter* chef;
struct angestellter* bestie;
};
typedef struct angestellter angestellter;
int main(void) {
angestellter asterix = { "Asterix", NULL, NULL };
angestellter majestix = { "Majestix", NULL, NULL };
angestellter* obelix;
obelix = (angestellter*)malloc(sizeof(angestellter));
strcpy(obelix->name, "Obelix");
asterix.chef = &majestix;
obelix->chef = &majestix;
asterix.bestie = obelix;
obelix->bestie = &asterix;
free(obelix);
obelix = NULL;
}