Get the App
SLTechnology News&Howtos  ›  Development  › 

What is a Go null pointer?

Shulou Source: shulou.com Published: 2022-06-01 02:31:33 10月02日 Update

This article mainly introduces the relevant knowledge of what the Go null pointer is. The content is detailed and easy to understand. The operation is simple and fast. It has certain reference value. I believe everyone will gain something after reading this article. Let's take a look at it.

Go null pointer

When a pointer is defined and not assigned to any variable, its value is nil.

The nil pointer is also known as the null pointer.

nil is conceptually the same as null, None, nil, and NULL in other languages, all of which refer to zero or null.

A pointer variable is usually abbreviated ptr.

Check out the following examples:

examples

package main

import "fmt"

func main() {

var ptr *int

fmt.Printf("ptr value is: %x\n", ptr )

}

The output of the above example is:

The value of ptr is: 0

Empty pointer judgment:

if(ptr != nil) /* ptr not null pointer */if(ptr == nil) /* ptr is a null pointer */About "Go null pointer is what" The content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of the knowledge of "Go empty pointer." If you still want to learn more knowledge, please pay attention to the industry information channel.

Tags: Pointers examples knowledge content variables articles values easy to operate articles easy to understand more concepts look results abbreviations industry language information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno MySQL Xiaomi MariaDB