Todo List - Zig Typing CST Test
Loading…
Todo List — Zig Code
Adds and removes tasks from a todo list.
const std = @import("std");
var todos: [10]?[]const u8 = [_]?[]const u8{null} ** 10;
var count: usize = 0;
fn addTask(task: []const u8) void {
if (count < todos.len) {
todos[count] = task;
count += 1;
}
}
fn removeTask(index: usize) void {
if (index < count) {
for (index..count-1) |i| {
todos[i] = todos[i+1];
}
count -= 1;
}
}
fn printTasks() void {
for (0..count) |i| {
std.debug.print("{d}: {s}\n", .{i+1, todos[i]});
}
std.debug.print("----------------\n", .{});
}
pub fn main() void {
addTask("Buy milk");
addTask("Write Zig code");
printTasks();
removeTask(0);
printTasks();
}Zig Language Guide
Zig is a general-purpose, statically typed, compiled programming language designed for robustness, optimal performance, and simplicity. It emphasizes manual memory management, safety features, cross-compilation, and direct interoperability with C, making it ideal for system programming, embedded development, and high-performance applications.
Primary Use Cases
- ▸System programming and OS development
- ▸Embedded and bare-metal applications
- ▸High-performance libraries and tools
- ▸Cross-platform and cross-compiler projects
- ▸Interfacing with C libraries and APIs
Notable Features
- ▸Manual memory management with safety
- ▸Comptime (compile-time) execution
- ▸Direct C interoperability
- ▸Error unions and optional types
- ▸Cross-compilation built-in
Origin & Creator
Created by Andrew Kelley in 2015 with the goal of replacing C while providing safer and more readable system programming constructs.
Industrial Note
Zig is gaining traction in system-level programming, embedded device firmware, WebAssembly development, game engine tooling, and low-level networking applications.