1. Home
  2. /
  3. Zig Typing Test
  4. /
  5. Counter and Theme Toggle

Counter and Theme Toggle - Zig Typing CST Test

Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const std = @import("std");
var count: i32 = 0;
var isDark: bool = false;

fn updateUI() void {
std.debug.print("Counter: {d}\n", .{count});
std.debug.print("Theme: {s}\n", .{ if (isDark) "Dark" else "Light" });
}

fn increment() void {
count += 1;
updateUI();
}

fn decrement() void {
count -= 1;
updateUI();
}

fn reset() void {
count = 0;
updateUI();
}

fn toggleTheme() void {
isDark = !isDark;
updateUI();
}

pub fn main() void {
updateUI();
increment();
increment();
toggleTheme();
decrement();
reset();
}
Coding works best on desktop or with an external keyboard.
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.

Counter and Theme Toggle — Zig Code

Demonstrates a simple counter with theme toggling using Zig variables and functions.

const std = @import("std");
var count: i32 = 0;
var isDark: bool = false;

fn updateUI() void {
	std.debug.print("Counter: {d}\n", .{count});
	std.debug.print("Theme: {s}\n", .{ if (isDark) "Dark" else "Light" });
}

fn increment() void {
	count += 1;
	updateUI();
}

fn decrement() void {
	count -= 1;
	updateUI();
}

fn reset() void {
	count = 0;
	updateUI();
}

fn toggleTheme() void {
	isDark = !isDark;
	updateUI();
}

pub fn main() void {
	updateUI();
	increment();
	increment();
	toggleTheme();
	decrement();
	reset();
}

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.

Quick Explain

  • ▸Zig is a compiled language that provides fine-grained control over memory and system resources.
  • ▸It combines simplicity with modern safety features like optional types and error handling.
  • ▸Commonly used in operating systems, game engines, embedded systems, and performance-critical applications.

Core Features

  • ▸Statically typed with no hidden control flow
  • ▸Comptime metaprogramming
  • ▸Direct access to pointers and memory
  • ▸Simple syntax for performance and clarity
  • ▸No hidden allocations or runtime surprises

Learning Path

  • ▸Learn basic syntax and data types
  • ▸Understand slices, structs, and pointers
  • ▸Practice error unions and optional types
  • ▸Use `comptime` for compile-time code
  • ▸Explore C interop and cross-compilation

Practical Examples

  • ▸Writing a custom memory allocator
  • ▸Creating a cross-platform CLI tool
  • ▸Interfacing with a C library
  • ▸Developing a small embedded firmware
  • ▸Implementing a high-performance networking server

Comparisons

  • ▸More memory-safe than C, less than Rust
  • ▸Simpler syntax than C++
  • ▸Cross-compilation easier than Go or Rust
  • ▸Less standard library than C++ or Rust
  • ▸Closer to hardware than Python or Java

Strengths

  • ▸High performance and predictable behavior
  • ▸Minimal runtime overhead
  • ▸Cross-platform compilation support
  • ▸Strong C interop for library reuse
  • ▸Compile-time code execution for flexibility

Limitations

  • ▸Smaller ecosystem than C/C++ or Rust
  • ▸No garbage collector; manual memory management required
  • ▸Limited standard library compared to mature languages
  • ▸Fewer learning resources and tutorials
  • ▸Some advanced abstractions require verbose code

When NOT to Use

  • ▸Rapid application development
  • ▸Garbage-collected environments
  • ▸Large ecosystem libraries required
  • ▸UI-heavy applications
  • ▸Managed runtime platforms

Cheat Sheet

  • ▸var x: i32 = 42 - declare variable
  • ▸fn add(a: i32, b: i32) i32 { return a+b; } - function
  • ▸const slice = []u8{1,2,3} - array/slice
  • ▸errdefer mem.free(ptr) - error-safe cleanup
  • ▸comptime { ... } - compile-time execution

FAQ

  • ▸Is Zig production-ready?
  • ▸Yes - suitable for systems programming and embedded projects.
  • ▸Can Zig replace C?
  • ▸It can in many scenarios, with safer and modern syntax.
  • ▸Does Zig have a garbage collector?
  • ▸No - manual memory management is used.
  • ▸Is Zig cross-platform?
  • ▸Yes - built-in cross-compilation for many targets.
  • ▸Is Zig suitable for beginners?
  • ▸Yes, for systems programming basics, though low-level concepts are required.

30-Day Skill Plan

  • ▸Week 1: Syntax, variables, functions
  • ▸Week 2: Pointers, slices, memory management
  • ▸Week 3: Error unions and optional types
  • ▸Week 4: Comptime metaprogramming
  • ▸Week 5: Cross-compilation and C integration

Final Summary

  • ▸Zig is a modern system programming language designed for safety, performance, and simplicity.
  • ▸It excels at low-level programming, embedded development, and cross-platform compilation.
  • ▸Zig combines C interoperability, manual memory management, and compile-time code execution.
  • ▸Ideal for developers who want control over performance and hardware without unnecessary runtime overhead.

Project Structure

  • ▸src/ - source code files
  • ▸build.zig - build configuration script
  • ▸tests/ - test files
  • ▸lib/ - optional libraries
  • ▸bin/ - compiled executables

Monetization

  • ▸Commercial libraries
  • ▸Embedded firmware products
  • ▸High-performance computing tools
  • ▸CLI utility software
  • ▸Game engine components

Productivity Tips

  • ▸Use `zig fmt` for consistent formatting
  • ▸Leverage `comptime` for compile-time checks
  • ▸Test code frequently with `zig test`
  • ▸Cross-compile regularly to verify targets
  • ▸Document error unions and memory usage

Basic Concepts

  • ▸Comptime code execution
  • ▸Error unions and error handling
  • ▸Optional types and pointer management
  • ▸Slices, arrays, and structs
  • ▸Direct C interoperability

Official Docs

  • ▸Zig Official Documentation
  • ▸Zig Learn Page
  • ▸Zig GitHub Repository

More Zig Typing Exercises

Zig Random Number GeneratorZig Todo ListZig Dice RollerZig Countdown TimerZig Prime CheckerZig Temperature ConverterZig Shopping CartZig Name GreetingZig Stopwatch

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher