Fixed-Size Arrays
Declare and index compile-time sized arrays.
Fixed-Size Arrays is a free Zig Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Zig Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What an Array Holds
An array stores a fixed number of values of the same type, laid out one after another in a single block of memory. 📦
The Length Is Fixed
In Zig the length is part of the array's type and is decided at compile time. It can never grow or shrink once declared.
Declaring an Array
You write the count in square brackets, then the element type. This [3]i32 holds exactly three signed integers.
const nums = [3]i32{ 10, 20, 30 };Let Zig Count for You
Use an underscore for the size and Zig infers it from the values you list. Here [_]i32 becomes a three-element array.
const nums = [_]i32{ 1, 2, 3 };Indexing Starts at Zero
Reach an element by its index in square brackets. Indices begin at 0, so nums[0] is the very first value.
const first = nums[0];Asking for the Length
Every array exposes its size through the len field. It is known at compile time and never changes.
const count = nums.len; // 3Bounds Are Checked
Reading past the end is caught for you. In safe builds an out-of-bounds index triggers a runtime panic instead of silent corruption.
Filling with One Value
Repeat a single element across the whole array using the ** operator. This makes five zeros without typing each one.
const zeros = [_]u8{0} ** 5;Arrays Are Value Types
Assigning one array to another copies every element. The two arrays are independent, so changing one leaves the other untouched.
Mutating Elements
Declare the array with var to change elements later. Then assign through an index to update a single slot.
var scores = [_]i32{ 0, 0, 0 };
scores[1] = 99;Arrays of Any Type
Elements can be any type, even other arrays. A [2][3]i32 is a small grid: two rows of three integers each.
const grid = [2][3]i32{ .{ 1, 2, 3 }, .{ 4, 5, 6 } };Quick Check
You declared const nums = [_]i32{ 1, 2, 3 }. What does nums.len evaluate to?
Recap
A fixed-size array packs same-type values together: length is part of the type, indices start at 0, and access stays bounds-checked. 🎯
Frequently asked questions
Is the “Fixed-Size Arrays” lesson free?
Yes — the full text of “Fixed-Size Arrays” is free to read here on the web, and the Zig Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Zig Academy course, upgrade to CoddyKit PRO.
What will I learn in “Fixed-Size Arrays”?
Declare and index compile-time sized arrays. You practise Zig Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Zig Academy?
No prior experience is required. Zig Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Fixed-Size Arrays” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Zig Academy lesson?
Yes. Every Zig Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.