How to print the contents of a slice in Go?
Hello everyone! I just started learning Go and encountered a simple but unclear problem.
\n\nI'm trying to print the contents of a slice, but instead of values I get something strange like [0x...]. Here's my code:
package main\n\nimport "fmt"\n\nfunc main() {\n arr := []int{10, 20, 30, 40, 50}\n fmt.Println(arr)\n}\n\n\nWhen I run the program, it prints something like [10 20 30 40 50] — this works! But when I try to print a slice of strings or structs, everything breaks. Here's an example:
package main\n\nimport "fmt"\n\ntype User struct {\n Name string\n Age int\n}\n\nfunc main() {\n users := []User{\n {"Alice", 30},\n {"Bob", 25},\n }\n fmt.Println(users)\n}\n No answers yet.
Log in to leave an answer
Blogs
TypeScript from Scratch in 2025: A Complete Guide for Beginners