You are previewing The Go Programming Language Phrasebook.

The Go Programming Language Phrasebook

Cover of The Go Programming Language Phrasebook by David Chisnall Published by Addison-Wesley Professional
O'Reilly logo

5. Arrays and Slices

Almost every programming language has a data structure that it calls an array, but the exact semantics vary considerably. In some languages, an array is a dynamically resizeable ordered collection of objects. In others, it’s a block of memory, with some vague hint that it probably contains variables of a specific type.

In Go, arrays are a very low-level data structure. Like C arrays, they are simply blocks of memory, but there are some important differences. Remember that Go does not permit pointer arithmetic. In C, array subscripting is just another way of writing pointer arithmetic, and you can use array and pointer types almost interchangeably.

In Go, pointers and arrays are distinct types. Because arrays and pointers ...

The best content for your career. Discover unlimited learning on demand for around $1/day.