From b256c9fe741ea03af2d3ac09be5fba029f1028cd Mon Sep 17 00:00:00 2001
From: Peter Gerwinski <peter.gerwinski@hs-bochum.de>
Date: Mon, 15 Nov 2021 14:17:33 +0100
Subject: [PATCH] Beispiel-Programme 15.11.2021

---
 20211115/addresses-1.c        | 10 ++++++++++
 20211115/addresses-2.c        | 18 ++++++++++++++++++
 20211115/addresses-3.c        | 18 ++++++++++++++++++
 20211115/addresses-4.c        | 18 ++++++++++++++++++
 20211115/addresses-5.c        | 18 ++++++++++++++++++
 20211115/addresses-6.c        | 18 ++++++++++++++++++
 20211115/arrays-pointers-1.c  |  9 +++++++++
 20211115/arrays-pointers-10.c |  9 +++++++++
 20211115/arrays-pointers-11.c |  9 +++++++++
 20211115/arrays-pointers-12.c |  9 +++++++++
 20211115/arrays-pointers-13.c |  8 ++++++++
 20211115/arrays-pointers-14.c |  9 +++++++++
 20211115/arrays-pointers-15.c |  9 +++++++++
 20211115/arrays-pointers-16.c |  9 +++++++++
 20211115/arrays-pointers-17.c |  9 +++++++++
 20211115/arrays-pointers-18.c |  8 ++++++++
 20211115/arrays-pointers-19.c |  9 +++++++++
 20211115/arrays-pointers-2.c  |  9 +++++++++
 20211115/arrays-pointers-3.c  |  9 +++++++++
 20211115/arrays-pointers-4.c  | 10 ++++++++++
 20211115/arrays-pointers-5.c  |  9 +++++++++
 20211115/arrays-pointers-6.c  | 11 +++++++++++
 20211115/arrays-pointers-7.c  | 11 +++++++++++
 20211115/arrays-pointers-8.c  | 11 +++++++++++
 20211115/arrays-pointers-9.c  | 11 +++++++++++
 25 files changed, 278 insertions(+)
 create mode 100644 20211115/addresses-1.c
 create mode 100644 20211115/addresses-2.c
 create mode 100644 20211115/addresses-3.c
 create mode 100644 20211115/addresses-4.c
 create mode 100644 20211115/addresses-5.c
 create mode 100644 20211115/addresses-6.c
 create mode 100644 20211115/arrays-pointers-1.c
 create mode 100644 20211115/arrays-pointers-10.c
 create mode 100644 20211115/arrays-pointers-11.c
 create mode 100644 20211115/arrays-pointers-12.c
 create mode 100644 20211115/arrays-pointers-13.c
 create mode 100644 20211115/arrays-pointers-14.c
 create mode 100644 20211115/arrays-pointers-15.c
 create mode 100644 20211115/arrays-pointers-16.c
 create mode 100644 20211115/arrays-pointers-17.c
 create mode 100644 20211115/arrays-pointers-18.c
 create mode 100644 20211115/arrays-pointers-19.c
 create mode 100644 20211115/arrays-pointers-2.c
 create mode 100644 20211115/arrays-pointers-3.c
 create mode 100644 20211115/arrays-pointers-4.c
 create mode 100644 20211115/arrays-pointers-5.c
 create mode 100644 20211115/arrays-pointers-6.c
 create mode 100644 20211115/arrays-pointers-7.c
 create mode 100644 20211115/arrays-pointers-8.c
 create mode 100644 20211115/arrays-pointers-9.c

diff --git a/20211115/addresses-1.c b/20211115/addresses-1.c
new file mode 100644
index 0000000..935be56
--- /dev/null
+++ b/20211115/addresses-1.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include <stdint.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  uint64_t a = hello;
+  printf ("a = %lu\n", a);
+  return 0;
+}
diff --git a/20211115/addresses-2.c b/20211115/addresses-2.c
new file mode 100644
index 0000000..338bbbc
--- /dev/null
+++ b/20211115/addresses-2.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdint.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  uint64_t a = hello;
+  uint32_t b = hello;
+  uint16_t c = hello;
+  uint8_t d = hello;
+  char e = hello;
+  printf ("a = %lu\n", a);
+  printf ("b = %u\n", b);
+  printf ("c = %hu\n", c);
+  printf ("d = %hhu\n", d);
+  printf ("e = %d\n", e);
+  return 0;
+}
diff --git a/20211115/addresses-3.c b/20211115/addresses-3.c
new file mode 100644
index 0000000..58bf55d
--- /dev/null
+++ b/20211115/addresses-3.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdint.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  uint64_t a = hello;
+  uint32_t b = hello;
+  uint16_t c = hello;
+  uint8_t d = hello;
+  char e = hello;
+  printf ("a = %016lx\n", a);
+  printf ("b = %08x\n", b);
+  printf ("c = %04x\n", c);
+  printf ("d = %02x\n", d);
+  printf ("e = %02x\n", e);
+  return 0;
+}
diff --git a/20211115/addresses-4.c b/20211115/addresses-4.c
new file mode 100644
index 0000000..3b9d9f3
--- /dev/null
+++ b/20211115/addresses-4.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdint.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  uint64_t a = (uint64_t) hello;
+  uint32_t b = (uint32_t) hello;
+  uint16_t c = (uint16_t) hello;
+  uint8_t d = (uint8_t)  hello;
+  char e = (char) hello;
+  printf ("a = %016lx\n", a);
+  printf ("b = %08x\n", b);
+  printf ("c = %04x\n", c);
+  printf ("d = %02x\n", d);
+  printf ("e = %02x\n", e);
+  return 0;
+}
diff --git a/20211115/addresses-5.c b/20211115/addresses-5.c
new file mode 100644
index 0000000..8854d92
--- /dev/null
+++ b/20211115/addresses-5.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdint.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  uint64_t a = (uint64_t) hello;
+  uint32_t b = (uint64_t) hello;
+  uint16_t c = (uint64_t) hello;
+  uint8_t d = (uint64_t)  hello;
+  char e = (uint64_t) hello;
+  printf ("a = %016lx\n", a);
+  printf ("b = %08x\n", b);
+  printf ("c = %04x\n", c);
+  printf ("d = %02x\n", d);
+  printf ("e = %02x\n", e);
+  return 0;
+}
diff --git a/20211115/addresses-6.c b/20211115/addresses-6.c
new file mode 100644
index 0000000..6f11d43
--- /dev/null
+++ b/20211115/addresses-6.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdint.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  uint64_t a = (size_t) hello;
+  uint32_t b = (size_t) hello;
+  uint16_t c = (size_t) hello;
+  uint8_t d = (size_t)  hello;
+  char e = (size_t) hello;
+  printf ("a = %016lx\n", a);
+  printf ("b = %08x\n", b);
+  printf ("c = %04x\n", c);
+  printf ("d = %02x\n", d);
+  printf ("e = %02x\n", e);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-1.c b/20211115/arrays-pointers-1.c
new file mode 100644
index 0000000..331e8d3
--- /dev/null
+++ b/20211115/arrays-pointers-1.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char hello[] = "Hello, world!";
+  char *p = hello;
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-10.c b/20211115/arrays-pointers-10.c
new file mode 100644
index 0000000..059013b
--- /dev/null
+++ b/20211115/arrays-pointers-10.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char *p = hello;
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-11.c b/20211115/arrays-pointers-11.c
new file mode 100644
index 0000000..c59ae2c
--- /dev/null
+++ b/20211115/arrays-pointers-11.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char p[] = { hello };
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-12.c b/20211115/arrays-pointers-12.c
new file mode 100644
index 0000000..5a1f2bb
--- /dev/null
+++ b/20211115/arrays-pointers-12.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char p[] = { hello };  /* ein Element des Arrays initialisieren */
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-13.c b/20211115/arrays-pointers-13.c
new file mode 100644
index 0000000..ef79bf6
--- /dev/null
+++ b/20211115/arrays-pointers-13.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char p[14] = { '*' };  /* ein Element des Arrays initialisieren */
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-14.c b/20211115/arrays-pointers-14.c
new file mode 100644
index 0000000..aa6c117
--- /dev/null
+++ b/20211115/arrays-pointers-14.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char *p[14] = { hello };  /* ein Element des Arrays initialisieren */
+  printf ("%s\n", p[1]);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-15.c b/20211115/arrays-pointers-15.c
new file mode 100644
index 0000000..fa859c0
--- /dev/null
+++ b/20211115/arrays-pointers-15.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char *p[14] = { hello };  /* ein Element des Arrays initialisieren */
+  printf ("%s\n", p[0]);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-16.c b/20211115/arrays-pointers-16.c
new file mode 100644
index 0000000..2ac4390
--- /dev/null
+++ b/20211115/arrays-pointers-16.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char p[] = { hello - 150 };  /* ein Element des Arrays initialisieren */
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-17.c b/20211115/arrays-pointers-17.c
new file mode 100644
index 0000000..d290e79
--- /dev/null
+++ b/20211115/arrays-pointers-17.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char p[] = { hello + 'a' };  /* ein Element des Arrays initialisieren */
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-18.c b/20211115/arrays-pointers-18.c
new file mode 100644
index 0000000..8d39757
--- /dev/null
+++ b/20211115/arrays-pointers-18.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char p[] = { 4 + 'a' };  /* ein Element des Arrays initialisieren */
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-19.c b/20211115/arrays-pointers-19.c
new file mode 100644
index 0000000..e975ca5
--- /dev/null
+++ b/20211115/arrays-pointers-19.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *hello = "Hallo, Welt!";
+  char p[] = { hello + 'a' };  /* ein Element des Arrays initialisieren */
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-2.c b/20211115/arrays-pointers-2.c
new file mode 100644
index 0000000..42e0f3d
--- /dev/null
+++ b/20211115/arrays-pointers-2.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char p[] = hello;
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-3.c b/20211115/arrays-pointers-3.c
new file mode 100644
index 0000000..7f489cc
--- /dev/null
+++ b/20211115/arrays-pointers-3.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  int a = 3;
+  int b = a;
+  printf ("%d\n", b);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-4.c b/20211115/arrays-pointers-4.c
new file mode 100644
index 0000000..9e9335e
--- /dev/null
+++ b/20211115/arrays-pointers-4.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int a = 3;
+int b = a;
+
+int main (void)
+{
+  printf ("%d\n", b);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-5.c b/20211115/arrays-pointers-5.c
new file mode 100644
index 0000000..e805a37
--- /dev/null
+++ b/20211115/arrays-pointers-5.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char p[13] = hello;
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-6.c b/20211115/arrays-pointers-6.c
new file mode 100644
index 0000000..0b6560d
--- /dev/null
+++ b/20211115/arrays-pointers-6.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <string.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char p[13];
+  strcpy (p, hello);
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-7.c b/20211115/arrays-pointers-7.c
new file mode 100644
index 0000000..26a064b
--- /dev/null
+++ b/20211115/arrays-pointers-7.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <string.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char p[14];
+  strcpy (p, hello);
+  printf ("%s\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-8.c b/20211115/arrays-pointers-8.c
new file mode 100644
index 0000000..928ecb4
--- /dev/null
+++ b/20211115/arrays-pointers-8.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <string.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char p[14];
+  strcpy (p, hello);
+  printf ("%c\n", p);
+  return 0;
+}
diff --git a/20211115/arrays-pointers-9.c b/20211115/arrays-pointers-9.c
new file mode 100644
index 0000000..ebeae79
--- /dev/null
+++ b/20211115/arrays-pointers-9.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <string.h>
+
+int main (void)
+{
+  char *hello = "Hello, world!";
+  char p[14];
+  strcpy (p, hello);
+  printf ("%c\n", p[1]);
+  return 0;
+}
-- 
GitLab