Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Map Declaration and Initialization | Intro to Structs & Maps
Introduction to GoLang

Map Declaration and InitializationMap Declaration and Initialization

We can declare an empty map using the make() function. Below is the syntax we need to follow:

Here, mapName is the name of the map, keyType is the expected type of the keys, and valueType is the expected type of the values. The term map is a keyword.

We can declare a map called courseData with keys of type string and values of type int.

go

index.go

If we attempt to output this map, we will receive an output indicating an empty map:

index

We can initialize a map with some data using the following syntax:

Note

You can place or omit spaces in the map declaration syntax; therefore, both map[keyType]valueType and map [keyType] valueType are valid.

Using the above syntax, we can create a map that has some initial data in it:

go

index.go

Which syntax is correct for creating a new empty map?

Selecione a resposta correta

Tudo estava claro?

Seção 6. Capítulo 5
course content

Conteúdo do Curso

Introduction to GoLang

Map Declaration and InitializationMap Declaration and Initialization

We can declare an empty map using the make() function. Below is the syntax we need to follow:

Here, mapName is the name of the map, keyType is the expected type of the keys, and valueType is the expected type of the values. The term map is a keyword.

We can declare a map called courseData with keys of type string and values of type int.

go

index.go

If we attempt to output this map, we will receive an output indicating an empty map:

index

We can initialize a map with some data using the following syntax:

Note

You can place or omit spaces in the map declaration syntax; therefore, both map[keyType]valueType and map [keyType] valueType are valid.

Using the above syntax, we can create a map that has some initial data in it:

go

index.go

Which syntax is correct for creating a new empty map?

Selecione a resposta correta

Tudo estava claro?

Seção 6. Capítulo 5
some-alt