×

Go Tutorial

Go Basics

Go Variables

Go Literals

Go Type Handling

Go Operators

Go Decision Making

Go Loops

Go Functions

Go String

Go Arrays

Go Slices

Go Maps

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

What is the default value of a pointer in Go language?

In this tutorial, we are going to learn about the pointer variable and the default value of a pointer variable in the Go language.
Submitted by IncludeHelp, on October 02, 2021

A pointer stores the memory address of a value (variable). The default value of a pointer in the Go programming language is nil.

Example:

// Golang program to demonstrate the
// default value of a pointer variable

package main

import "fmt"

func main() {
	var num *int

	fmt.Println("The default value of a pointer variable:", num)
}

Output:

The default value of a pointer variable: <nil>

Example 2: Checking whether pointer is nil or not

// Golang program to demonstrate the
// default value of a pointer variable

package main

import "fmt"

func main() {
	var num *int

	if num == nil {
		fmt.Println("Yes, the pointer is nil")
	} else {
		fmt.Println("No, the pointer is not nil")
	}
}

Output:

Yes, the pointer is nil

Golang FAQ »

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.