Pointers

This lesson discusses how pointers are used in the Go language.

We'll cover the following

Introduction

Unlike Java and .NET, Go gives the programmers control over which data structure is a pointer and which is not; however, calculations with pointer values are not supported in Go programs. By giving the programmer control over basic memory layout, Go provides you the ability to control the total size of a given collection of data structures, the number of allocations, and the memory access patterns; all of which are important for building systems that perform well.

Pointers are important for performance and indispensable if you want to do systems programming close to the operating system and network. Because pointers are somewhat unknown to contemporary OO-programmers, we will explain them here and in the coming chapters in depth.

Pointers in Go

Programs store values in memory, and each memory block (or word) has an address, which is usually represented as a hexadecimal number, like 0x6b0820 or 0xf84001d7f0. Go has the address-of operator &, which, when placed before a variable, gives us the memory address of that variable. For example:

Get hands-on with 1400+ tech skills courses.