Add README.md
This commit is contained in:
181
src/c_examples/README.md
Normal file
181
src/c_examples/README.md
Normal file
@@ -0,0 +1,181 @@
|
||||
# 📚 Programmierkonzepte Universell - Code-Beispiele
|
||||
|
||||
*Praktische Beispiele für den interaktiven Programmierkurs*
|
||||
|
||||
---
|
||||
|
||||
## 📁 Repository-Struktur
|
||||
|
||||
```
|
||||
code-examples/
|
||||
├── README.md # Diese Datei
|
||||
├── Makefile # Build-System
|
||||
├── module1_memory.c # Memory-Modell (Stack vs Heap)
|
||||
├── module2_datatypes.c # Datentypen und Grenzen
|
||||
├── module3_controlflow.c # Flusskontrolle (If, For, While)
|
||||
├── module4_functions.c # Funktionen und Rekursion
|
||||
├── module5_datastructures.c # Arrays, Listen, Stack, Queue
|
||||
├── module6_pointers.c # Pointer und Pointer-Arithmetik
|
||||
├── module7_oop_in_c.c # OOP-Konzepte in C
|
||||
├── module8_modularization.c # Modularisierung und Patterns
|
||||
└── cpp_comparison/ # C++ Vergleichsbeispiele
|
||||
├── module7_oop_in_cpp.cpp # Gleiche OOP-Beispiele in C++
|
||||
└── module8_stl.cpp # STL-Beispiele (Vektor, Map, etc.)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Schnellstart
|
||||
|
||||
### Kompilieren und Ausführen
|
||||
|
||||
```bash
|
||||
# Einzelnes Modul kompilieren
|
||||
gcc -o module1 module1_memory.c -Wall -Wextra
|
||||
./module1
|
||||
|
||||
# Oder mit Make
|
||||
make module1
|
||||
./module1
|
||||
|
||||
# Alle Module kompilieren
|
||||
make all
|
||||
```
|
||||
|
||||
### C++ Vergleichsbeispiele
|
||||
|
||||
```bash
|
||||
# C++ Beispiele kompilieren
|
||||
g++ -std=c++17 -o oop_cpp cpp_comparison/module7_oop_in_cpp.cpp
|
||||
./oop_cpp
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📖 Modul-Übersicht
|
||||
|
||||
| Modul | Datei | Konzepte | C++ Gegenstück |
|
||||
|-------|-------|----------|----------------|
|
||||
| 1 | `module1_memory.c` | Stack, Heap, malloc/free | `new/delete`, Smart Pointer |
|
||||
| 2 | `module2_datatypes.c` | Typen, Overflow, Fixed-Width | `int32_t`, `auto` |
|
||||
| 3 | `module3_controlflow.c` | If, For, While, Switch | Gleich |
|
||||
| 4 | `module4_functions.c` | Parameter, Rekursion, Function Pointers | References, Lambdas |
|
||||
| 5 | `module5_datastructures.c` | Vector, LinkedList, Stack, Queue | STL: `vector`, `list`, `stack`, `queue` |
|
||||
| 6 | `module6_pointers.c` | *, &, Pointer-Arithmetik | References `&`, Smart Pointer |
|
||||
| 7 | `module7_oop_in_c.c` | OOP mit Structs | `class`, `virtual`, `override` |
|
||||
| 8 | `module8_modularization.c` | MVC, Strategy Pattern | Namespaces, Templates |
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Wichtige Lernziele
|
||||
|
||||
### Nach Modul 1 (Memory)
|
||||
- [ ] Stack vs Heap erklären können
|
||||
- [ ] malloc/free korrekt verwenden
|
||||
- [ ] Memory Leaks erkennen und vermeiden
|
||||
|
||||
### Nach Modul 4 (Funktionen)
|
||||
- [ ] Call-by-Value vs Call-by-Reference verstehen
|
||||
- [ ] Rekursion (Base Case!) anwenden
|
||||
- [ ] Function Pointers nutzen
|
||||
|
||||
### Nach Modul 6 (Pointer)
|
||||
- [ ] `*`, `&` und Pointer-Arithmetik beherrschen
|
||||
- [ ] Double Pointer verstehen
|
||||
- [ ] Dangling Pointers vermeiden
|
||||
|
||||
### Nach Modul 8 (OOP & Modular)
|
||||
- [ ] OOP-Konzepte in C simulieren
|
||||
- [ ] Design Patterns (Strategy, Singleton) anwenden
|
||||
- [ ] Modulare Architektur (MVC) verstehen
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Build-System (Makefile)
|
||||
|
||||
```makefile
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
CFLAGS = -Wall -Wextra -std=c99
|
||||
CXXFLAGS = -Wall -Wextra -std=c++17
|
||||
|
||||
MODULES = module1 module2 module3 module4 module5 module6 module7 module8
|
||||
|
||||
all: $(MODULES)
|
||||
|
||||
module1: module1_memory.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
module2: module2_datatypes.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
module3: module3_controlflow.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
module4: module4_functions.c
|
||||
$(CC) $(CFLAGS) -o $@ $< -lm
|
||||
|
||||
module5: module5_datastructures.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
module6: module6_pointers.c
|
||||
$(CC) $(CFLAGS) -o $@ $< -lm
|
||||
|
||||
module7: module7_oop_in_c.c
|
||||
$(CC) $(CFLAGS) -o $@ $< -lm
|
||||
|
||||
module8: module8_modularization.c
|
||||
$(CC) $(CFLAGS) -o $@ $< -lm
|
||||
|
||||
cpp_oop: cpp_comparison/module7_oop_in_cpp.cpp
|
||||
$(CXX) $(CXXFLAGS) -o $@ $<
|
||||
|
||||
cpp_stl: cpp_comparison/module8_stl.cpp
|
||||
$(CXX) $(CXXFLAGS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(MODULES) cpp_oop cpp_stl
|
||||
|
||||
.PHONY: all clean
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎓 Vergleich: C vs C++
|
||||
|
||||
| Konzept | C | C++ |
|
||||
|---------|---|-----|
|
||||
| **Memory** | `malloc/free` | `new/delete`, Smart Pointer |
|
||||
| **Strings** | `char[]` (manuell) | `std::string` (automatisch) |
|
||||
| **Arrays** | Fixed oder dynamisch | `std::vector` (auto-resizing) |
|
||||
| **OOP** | Structs + Function Pointers | `class`, `virtual`, `override` |
|
||||
| **Generics** | `void*` (unsicher) | `template` (typsicher) |
|
||||
| **Module** | Header-Dateien | Namespaces, Modules (C++20) |
|
||||
|
||||
---
|
||||
|
||||
## 💡 Tipps
|
||||
|
||||
1. **Kompilieren mit Warnungen:** `-Wall -Wextra` zeigt potenzielle Fehler
|
||||
2. **Valgrind für Memory:** `valgrind --leak-check=full ./program`
|
||||
3. **Debugger nutzen:** `gdb ./program` für Step-by-Step
|
||||
4. **C++ als Referenz:** Wenn C zu komplex wird, schau wie C++ es löst
|
||||
|
||||
---
|
||||
|
||||
## 📚 Weitere Ressourcen
|
||||
|
||||
- **Kurs-Dokumentation:** `../programming-concepts-universal.md`
|
||||
- **Quizfragen:** `../quiz-fragen.md`
|
||||
- **Offizielle C-Dokumentation:** <https://en.cppreference.com/w/c>
|
||||
- **C++ Referenz:** <https://en.cppreference.com/w/cpp>
|
||||
|
||||
---
|
||||
|
||||
## 📝 Lizenz
|
||||
|
||||
Dieser Kurs und die Code-Beispiele sind für Bildungszwecke gedacht.
|
||||
|
||||
---
|
||||
|
||||
*Happy Coding! 🚀*
|
||||
Reference in New Issue
Block a user