1. Home
  2. /
  3. Zig-wasm
  4. /
  5. Zig WASM Fibonacci

Zig WASM Fibonacci - Zig-wasm Typing CST Test

Loading…

Zig WASM Fibonacci — Zig-wasm Code

Calculates the nth Fibonacci number recursively and prints it.

# zig/demo/fibonacci.zig
const std = @import("std");

fn fib(n: i32) i32 {
	if (n <= 1) return n;
	return fib(n - 1) + fib(n - 2);
}

pub export fn fibonacci(n: i32) void {
	std.debug.print("Fibonacci: {d}\n", .{fib(n)});
}

Zig-wasm Language Guide

Zig is a general-purpose programming language designed for robustness, optimality, and simplicity. With Zig-Wasm, developers can compile Zig code to WebAssembly, enabling high-performance, low-level applications in the browser or other Wasm runtimes.

Primary Use Cases

  • ▸Porting system-level libraries to WebAssembly
  • ▸High-performance game engines or simulations in the browser
  • ▸Cryptography, compression, or other CPU-intensive algorithms
  • ▸Replacing C/C++ Wasm modules with safer, simpler Zig code
  • ▸Low-level WASI (WebAssembly System Interface) applications

Notable Features

  • ▸Direct compilation to WebAssembly (Wasm32 target)
  • ▸No hidden runtime or garbage collector
  • ▸C interop for leveraging existing code
  • ▸Manual memory management with safety options
  • ▸Simple, readable, and maintainable syntax

Origin & Creator

Zig is created by Andrew Kelley, with the community contributing to language development, compiler improvements, and WebAssembly support.

Industrial Note

Zig-Wasm is particularly useful for developers who need predictable, high-performance WebAssembly modules, low-level memory control, or integration with C/C++ codebases for web execution.

More Zig-wasm Typing Exercises

Simple Zig WebAssembly ProgramZig WASM Add Two NumbersZig WASM Multiply Two NumbersZig WASM FactorialZig WASM Even CheckZig WASM Maximum of Two NumbersZig WASM Minimum of Two NumbersZig WASM Toggle BooleanZig WASM Print Array

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher