Go

Go Basics

Variables, constants, basic types, functions, packages, imports, control flow, defer

25 câu hỏi phỏng vấn·
Junior
1

What is the correct syntax to declare a variable in Go?

Câu trả lời

In Go, there are three main ways to declare a variable: var x int (explicit declaration with type), var x = 10 (declaration with type inference), and x := 10 (short declaration with inference, only inside functions). The short form := is most commonly used for local variables as it is concise and idiomatic.

2

What is the zero value of an int variable in Go?

Câu trả lời

In Go, all variables are initialized with a zero value by default if no value is provided during declaration. For numeric types (int, float64), the zero value is 0. For booleans it's false, for strings it's an empty string, and for pointers it's nil. This behavior ensures there are never uninitialized variables in Go.

3

What is the difference between var x int and x := 0 in Go?

Câu trả lời

var x int declares a variable with zero value (0) and an explicit type, while x := 0 uses short declaration with type inference. The short declaration := can only be used inside functions, while var can be used at package level. The := form is preferred for local variables as it is more concise and idiomatic.

4

How to declare a constant in Go?

5

What are the basic numeric types in Go?

+22 câu hỏi phỏng vấn

Nắm vững Go cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí