1 /* 2 * name_adresse.c 3 * 4 * Beispiel-Programm Speichernutzung per Name oder Adresse 5 * 6 * Autor: H.Drachenfels 7 * Erstellt am: 30.10.2015 / 10.11.2017 (C11) 8 */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 int main(void)
14 {
15 {
16 // Speichernutzung per Wertvariable:
17 int a = 0;
18 int b = 1;
19
20 b = a;
21
22 printf("a = %d\n", a);
23 printf("b = %d\n", b);
24 }
25
26 {
27 // Speichernutzung per Zeigervariable:
28 int *a = (int*) calloc(1, sizeof (int));
29 int *b = (int*) malloc(sizeof (int));
30
31 if (a == NULL || b == NULL)
32 {
33 printf("Speicherallokierungsfehler\n");
34 return 1;
35 }
36
37 *b = 1;
38
39 *b = *a;
40
41 printf("*%p = %d\n", (void*) a, *a);
42 printf("*%p = %d\n", (void*) b, *b);
43
44 free(a);
45 free(b);
46 }
47
48 return 0;
49 }
50