0Pricing
Zig Academy · Lektion

Compilezeit und Laufzeit

Was Zig vor der Ausführung auswerten kann.

Compilezeit und Laufzeit ist eine kostenlose Zig Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Zig Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Zig Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Two Times in One Program

Zig code lives in two worlds: things that happen while you compile, and things that happen while the program runs. Learning the split unlocks Zig's power. ⏱️

Run-Time Is the Familiar One

Run-time is everything that happens when your built binary executes: user input, file reads, and values you cannot know in advance.

Compile-Time Happens Earlier

Compile-time is work the Zig compiler does before a binary even exists. Some expressions get fully evaluated right there.

Constants Often Fold Away

A simple expression with known values can be computed during compilation. Zig folds it into a single constant in the final binary.

const minutes = 60 * 24;

comptime_int Has No Fixed Width

A bare integer literal starts life as a comptime_int. It has arbitrary precision until you pin it to a sized type like i32.

const big = 1_000_000_000_000;

The comptime Keyword

Put comptime in front of an expression to demand it be evaluated during compilation. If it cannot be, you get an error.

comptime {
    const x = 2 + 3;
}

Run-Time Values Stay at Run-Time

A value read from input is only known when the program runs. You cannot ask the compiler to evaluate it at compile-time.

comptime Can Run Real Logic

Compile-time is not just math. Zig can run loops and call functions at compile-time, as long as every input is known then.

const total = comptime sum(10);

Why Move Work to Compile-Time

Computing things during compilation means zero run-time cost. The answer is baked into the binary, so the program never recomputes it.

One Language for Both

The same Zig syntax serves both phases. There is no separate macro language: compile-time code is just ordinary Zig run early.

Errors Caught Before Run-Time

Because Zig evaluates known code early, many mistakes surface as compile errors. You fix them before the program ever runs.

Quick Check

You write a constant equal to 7 times 24. When is that multiplication performed?

Recap

Zig splits work into compile-time and run-time. Known values can be computed early for free, while unknown ones wait for execution. 🎯

Häufig gestellte Fragen

Ist die Lektion „Compilezeit und Laufzeit“ kostenlos?

Ja — der vollständige Text von „Compilezeit und Laufzeit“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Zig Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Zig Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Compilezeit und Laufzeit“?

Was Zig vor der Ausführung auswerten kann. Du übst Zig Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Zig Academy zu starten?

Keine Vorkenntnisse erforderlich. Zig Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „Compilezeit und Laufzeit“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Zig Academy-Lektion Code schreiben und ausführen?

Ja. Jede Zig Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Compilezeit und Laufzeit
  2. comptime-Parameter und -Werte
  3. Typen sind comptime-Werte
  4. inline for und entrollte Schleifen
← Zurück zu Zig Academy