Road to Golang pro — Pointer & Functions

Road to Golang pro — Pointer & Functions

A few words before we start. You can find the code used in this tutorial in this repository. You can find the full contents of Road to Go Pro here. If you missed the last one, you can find it via this link.

A few words before we start. You can find the code used in this tutorial in this [repository_](https://github.com/songx23/RoadToGoPro). You can find the full contents of Road to Go Pro [here_](https://medium.com/@songx/road-to-go-pro-f9d1f8a51fad). If you missed the last one, you can find it via this [link_](https://levelup.gitconnected.com/road-to-go-pro-flow-control-dfcc7b9a5395)._

We talked about flow controls and loops in the last part of the tutorial. In this one, we will cover pointers and functions. After finishing the first 4 parts of Road to Go Pro, you are well equipped to start writing scripts or console applications using Go.

Pointers

Image for post

Photo by Nathalie SPEHNER on Unsplash

If you have used C or C++, you already know what’s a pointer. However, in the most popular programming languages like Java, C#, Javascript, Python, etc. there’s no explicit syntax to represent pointers. I had no idea what it is when I first heard of this name.

In short, a pointer holds the underlying memory address of a value. Whoa, hold on, memory address? Isn’t Go a high-level programming language?

When do we even need to know about the memory addresses of variables?

That’s a good question but before exploring the answer, we need to take a quick detour. Let’s see how to declare pointers and how to use them in functions. Once we have covered these, it will be easier for you to understand the reasoning and examples below. So hang in there.

Declaring pointers

Whenever we declare a variable in Go, the compiler allocates a segment of memory to store it. The value of that variable is stored there until it is recycled by the garbage collector.

Pointers are composite data types. We form a pointer type by adding an * in front of the data type it points to. For instance, *string represents the type of a pointer pointing to a string-type variable.

To get the pointer value of an existing variable, we need to add an & in front of the variable.

golang go golang-tutorial golang-development

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Hire Dedicated Golang Developers | Golang Web Development Company

Hire dedicated GoLang developers from WebClues Infotech to build applications using Go language. Get best GoLang developers for your web development projects.

Golang Web Development:Th Best Programming Language in 2020

Golang Web Development is the new trend globally. Get all the details about the Golang development here. Hire Golang Developers.

Top Golang Web Development Company in India- Binmile

Binmile is a frontline Golang web development company offering Golang development solutions by experienced and professional web developers.

Go (Golang) Tutorial #2 - Your First Go File

In this Go tutorial we'll walk trough a simple Go file to explain the basics of how Go files & programs work.

Golang HTTP API With Gin Gonic - Go Tutorial

In this video I wanted to cover something different. I've been looking into Golang and I believe its a language that many people will adopt in the future. Its simple, fast and has an amazing ability to handle tasks concurrently. I plan on making on videos with Golang as I don't see much content out therefore go and I think this is a language people want to learn and I want to help with that.