Home > Backend Development > Golang > Is map in golang a pointer?

Is map in golang a pointer?

Release: 2019-12-24 11:39:36
Original
6699 people have browsed it

Is map in golang a pointer?

map in golang is not a pointer.

Pointer:

A pointer variable points to the memory address of a value.

Similar to variables and constants, you need to declare a pointer before using it. The pointer declaration format is as follows:

var var_name *var-type
Copy after login

var-type is the pointer type, var_name is the pointer variable name, and the * sign is used to specify that the variable is used as a pointer. The following are valid pointer declarations:

map:

Map is an unordered collection of key-value pairs. The most important point of Map is to quickly retrieve data through key. Key is similar to an index and points to the value of the data.

Map is a collection, so we can iterate over it just like arrays and slices. However, Map is unordered and we cannot determine the order in which it is returned. This is because Map is implemented using a hash table.

Define Map

You can use the built-in function make or the map keyword to define Map:

/* 声明变量,默认 map 是 nil */
var map_variable map[key_data_type]value_data_type
/* 使用 make 函数 */
map_variable := make(map[key_data_type]value_data_type)
Copy after login

If the map is not initialized, a nil map will be created. nil map cannot be used to store key-value pairs

For more golang knowledge, please pay attention to the PHP Chinese websitegolang tutorial column.

The above is the detailed content of Is map in golang a pointer?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template