Can you declared multiple types of variables in single declaration in Go?
Can you declared multiple types of variables in single declaration in Go?
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.
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.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.