Skip to content

Instantly share code, notes, and snippets.

@FooBarWidget
Last active June 13, 2020 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FooBarWidget/0539dd2d2840e51b1fd1908d1ecedd11 to your computer and use it in GitHub Desktop.
Save FooBarWidget/0539dd2d2840e51b1fd1908d1ecedd11 to your computer and use it in GitHub Desktop.

wat betreft je programma: hij doet niet wat je wilt omdat b een lokale variabel is. met &b wilde je eigenlijk een pointer pakken naar een entry binnen a. maar je hebt in feite een pointer gepakt naar de lokale variabel b. die b wordt gemuteerd door de range call, en de laatste mutatie zet de waarde van b op 9. daarom print het programma alleen maar 9

probeer dit eens:

	// Fill the pointer slice with the contents of the int slice
	for i, _ := range a {
		pa = append(pa, &a[i])
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment