Câu hỏi phỏng vấn Golang
Câu hỏi

Can you declared multiple types of variables in single declaration in Go?

Câu trả lời

In Go, you cannot declare multiple variables of different types in a single declaration if you are using the var keyword with the type specified for each variable. The Go language specification requires that if you are using the var keyword with type annotations, all variables in the declaration must be of the same type[1][2].

However, you can declare and initialize multiple variables of different types in a single line using the short variable declaration syntax :=, which allows for type inference. This means that the types of the variables are determined by the compiler based on the types of the corresponding initialization expressions[1][3].

For example, you can declare variables of different types in one line like this:

c, d, e := 1, 2, "whatever"

In this case, c and d would be of type int, and e would be of type string, as inferred by the compiler from the values provided.

If you want to explicitly state the types ...

junior

junior

Gợi ý câu hỏi phỏng vấn

junior

What are Goroutines?

middle

Have you worked with Go 2?

junior

How to efficiently concatenate strings in Go?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào