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~
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;
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!