# What Zig Is and Why It Exists — Zig

Source: https://www.geekswithgeeks.com/en/zig/f-what

> Describe Zig's goals, design principles and where it is used.

## A simple, explicit systems language

**Zig** is a general-purpose systems programming language and toolchain created by Andrew Kelley (first public release in 2016) and developed by the non-profit **Zig Software Foundation**. It aims to be a better C: as fast and low-level, but simpler and safer. Its design principles are **no hidden control flow** (no operator overloading, no exceptions, no implicit function calls such as destructors), **no hidden memory allocations** (functions that allocate take an **allocator** parameter), **explicit error handling** with error unions, and **compile-time code execution** (`comptime`) instead of a macro system or separate generics language. Zig has **optional safety checks** (bounds, integer overflow, null) that are on in debug and safe builds. It interoperates with C directly: it can import C headers, and its toolchain includes a drop-in C/C++ compiler (`zig cc`) with easy **cross-compilation** to many targets. Notable Zig projects include the **Bun** JavaScript runtime, the **TigerBeetle** financial database and the **Ghostty** terminal. Zig is **pre-1.0**: the language and especially the standard library still change between releases, so always check the documentation for the version you use.

## Zig's design principles

Explicit control flow, explicit allocation, explicit errors and compile-time execution.

![Four labelled tiles arranged around a lightning bolt logo-like shape: an arrow path, a memory block with a key, a warning triangle and a gear marked with a clock.](assets/figures/zig/section-1-map.svg) — Figure 1.1 — What "explicit" means in Zig.

## Hello, Zig

A first program with a type-safe formatted print.

```zig
const std = @import("std");

pub fn main() void {
    const language = "Zig";
    const year: u32 = 2016;

    // std.debug.print writes to stderr; arguments are an anonymous tuple
    std.debug.print("Hello from {s}, first released in {d}!\n", .{ language, year });

    var total: u32 = 0;
    for (1..11) |n| {          // 1 to 10 inclusive (the range end is exclusive)
        total += @as(u32, @intCast(n));  // n is usize; checked conversion to u32 in safe modes
    }
    std.debug.print("Sum of 1..10 = {d}\n", .{total});
}

// zig run hello.zig
```

## Note the version you learn

The examples in this course target Zig 0.15. The core language is fairly stable, but standard library APIs (I/O, containers, the build system) change between releases. When an example does not compile, check the release notes first.

**Quiz:** Which is a core Zig design principle?

- [x] No hidden control flow and no hidden allocations
- [ ] Hidden memory allocations for convenience
- [ ] Exceptions for all errors
- [ ] Garbage collection

*Answer:* No hidden control flow and no hidden allocations. Zig makes control flow, allocation and errors explicit.
