Arrays

You will learn

How to declare an array, read an item, and which index is the last one.

An array type is the length in square brackets followed by the item type: [5]u8 is five unsigned bytes. The value lists the items in square brackets. Index 0 holds the item at the start, so in an array of 5 the last index is 4. A test reads an item with PRIMES[4]. Keep the declared length and the list in step: the checker in this browser does not catch a length that disagrees with the list.

Open the interactive lesson →