Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Go initialize an array

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "how to initialize the array by Go". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to initialize the array by Go" can help you solve your doubts.

Initialize array

The following demonstrates array initialization:

Var balance = [5] float32 {1000.0, 2.0,3.4,7.0,50.0}

We can also quickly initialize the array while declaring it literally:

Balance: = [5] float32 {1000.0, 2.0,3.4,7.0,50.0}

If the length of the array is uncertain, you can use. Instead of the length of the array, the compiler deduces the length of the array based on the number of elements:

Var balance = [...] float32 {1000.0, 2.0,3.4,7.0,50.0} or balance: = [...] float32 {1000.0, 2.0,3.4,7.0,50.0}

If the length of the array is set, we can also initialize the element by specifying the subscript:

/ / initialize the elements with indexes 1 and 3 balance: = [5] float32 {1VOR 2.0pm 3JR 7.0}

The number of elements in the initialization array {} cannot be greater than the number in [].

If you ignore the numbers in [] and do not set the size of the array, the Go language sets the size of the array based on the number of elements:

Balance [4] = 50.0

The above example reads the fifth element. Array elements can be read (or modified) by index (position), which starts at 0, the first element index is 0, the second index is 1, and so on.

After reading this, the article "how to initialize the array of Go" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report