Which of the following is a valid way to initialize a variable in Go?

  • var x = 5
  • var x int = 5
  • x := 5
  • x int = 5
In Go, the short variable declaration x := 5 is a valid way to initialize a variable. This syntax allows you to declare and initialize a variable without explicitly specifying its type, relying on type inference. It's a concise and idiomatic way to initialize variables in Go.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *