0Pricing
Zig Academy · Lesson

Anonymous Structs and Tuples

Create ad-hoc grouped values.

Sometimes You Need It Once

Not every grouping deserves a named type. Zig lets you write an anonymous struct inline, right where you use it.

Just Drop the Name

An anonymous struct literal starts with .{ and lists fields by name, with no type written before it.

const p = .{ .x = 1, .y = 2 };

All lessons in this course

  1. Declaring Structs and Fields
  2. Methods and the self Parameter
  3. Default Field Values
  4. Anonymous Structs and Tuples
← Back to Zig Academy