Home  >  Article  >  Backend Development  >  Record the pitfalls in for range in golang

Record the pitfalls in for range in golang

藏色散人
藏色散人forward
2022-11-24 16:57:206317browse

This article is written by the golang tutorial column to share with you a pitfall in the for range in the go language. If you have friends who have encountered the same problem, you can refer to it! Thank you~

Record the pitfalls in for range in golang

The pitfalls in the go language for range

Record the pitfalls in for range in golang

If you want to get the pointer , the reason for using this method

is that the for range loop only has := for the first time, and = from the second loop onwards (for the previous The variables are assigned values ​​instead of re-initialized, so they all correspond to the same pointer); so the pointer address is the same no matter how many times it is looped;

Record the pitfalls in for range in golang

The above is the detailed content of Record the pitfalls in for range in golang. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete